I have a bunch of strings of following pattern in text file 201194_2012110634 Appliance 130 AB i Some optional (Notes ) 300723_2017050006(2016111550) Device 16 AB i Note
The first part is serial, the 2nd is date. Device/Appliance name and model (about 10 possible different names) is the string after date number and before (including AB i)
I was able to isolate dates and serials using SERIAL=${line:0:6} YEAR=${line:7:4}
I'm trying to isolate Device name and note after that:
#!/bin/bash
while IFS= read line || [[ -n $line ]]; do
NAME=${line#*[a-zA-Z]}
STRINGAP='Appliance '"${line/#*Appliance/}"
The first approach is to take everything after the first letter appearing in line which gives me
NAME = ppliance 130 AB i Some optional (Notes )
The 2nd approach is to write tests for each of possible ~10 appliance/device names and then append appliance name after the subtracted test. Then test variable which actually matched Appliance / Device (or other name) and use that to input into the database..
Is it possible to write a line that would select everything, including first letter in a line in text file? Then I would subtract everything after AB i to get notes and everyting before AB i would become appliance name.
Aucun commentaire:
Enregistrer un commentaire