Hello everybody,
I am working on a project where I need to import gathered data into SQLite database table
the textfile I am working with looks like this:
Code:
NAME: "2811 chassis", DESCR: "2811 chassis"
PID: CISCO2811 , VID: V06 , SN: XXXXXXXXXXX
NAME: "WAN Interface Card - Serial 2A/S on Slot 0 SubSlot 0", DESCR: "WAN Interface Card - Serial 2A/S"
PID: WIC-2A/S , VID: V01, SN: XXXXXXXX
NAME: "WAN Interface Card - Serial 2T on Slot 0 SubSlot 2", DESCR: "WAN Interface Card - Serial 2T"
PID: WIC-2T , VID: V01, SN: XXXXXXXX
it can be anything from 1 two-line entry to as many as 15-20 two-line entries
what I want it to look like
Code:
2811 chassis|2811 chassis|CISCO2811|V06|XXXXXXXXXXX
WAN Interface Card - Serial 2A/S on Slot 0 SubSlot 0|WAN Interface Card - Serial 2A/S|WIC-2A/S|V01|XXXXXXXX
WAN Interface Card - Serial 2T on Slot 0 SubSlot 2|WAN Interface Card - Serial 2T|WIC-2T|V01|XXXXXXXX
as for the 1st line of each entry I managed to extract needed information using this sed command
Code:
sed -e "s/^.*\"\(.*\)\".*\"\(.*\)\".*$/\1\|\2\|/" sample.txt
I am struggling with the 2nd line of the entry
it always starts with 'PID: ' then comes the word I want to extract (it never contains any space) then comes variable amount of spaces followed by (,) and another space
after that always comes 'VID: ' followed by 3 characters I want to extract (it never contains any space)
that is followed by ', SN: ' and a word I want to extract (it never contains any space) after that may or may not follow variable amount os spaces. then END-OF-LINE
that is the structure of the file I need your help to process
thanks you very much in advance.