Hi All,
I would want to make a one liner (sed) that is able to extract a field form a log file bounded by two strings, however I wouldn't want to delete those lines that doesn't have this field but have an newline ( or a string, if possible) instead.
This would be particularly important since I would want to use paste command to generate a csv file from several files, each containing the value of the field.
For example
Input file:
Quote:
20120320 [field1,value1]
20120321 [field2,value2]
20120322 [field1,value3][field2,value4]
The expected output file would be
Quote:
value1
value3
The version I made for this purpose was:
Code:
leftPattern="[field1,"
rightPattern="]"
cat infile | psed "s/.*$leftPattern//g" | psed "s/$rightPattern.*//g" > outfile
but it ceratinly does rabish for line beginning with 20120321.
I guess this is not a very common use-case for sed, my gut feeling says branching is the solution but
I haven't found any reasonable track to follow yet.
Does anybody have a clue?
Thank you very much in advance,
Lev