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.
The expected output file would be
The version I made for this purpose was:
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,