I have a number of plain text files with similar but slightly different structure I need to extract a particular line from.
This line of text doesn't follow any particular pattern (i.e. its content is always different) and is not always in the same place in the file --- though is usually close to the beginning of the file.
These files are press releases (originally in PDF, converted to text on the fly with
pdftotext), and the line I need to extract is the subject, that I need to use as filename afterwards.
If I just run
sed -n '1p' on these files, extracting the very first line, sometimes I get the result I want, more often not.
A sample of the different results I get:
Title of the press release # correct result # wrong, here the first line is empty 29.9.2016 # wrong, here the first line contains the date PRESS RELEASE # also wrong, I would need to scan further down
These are pretty much all of the cases. What gives me hope is that, since these files have very similar structure and contain a title close to the beginning, if I keep scanning down sooner or later I will find what I'm looking for.
Is there any way to tell sed, in the same sed command, to try different patterns until a set of conditions in not met?
In my case I would need to tell sed to:
- check that the line is not empty
- check that the line doesn't contain a date
- check that the line doesn't contain the words "Press Release"
If none of the conditions are met, output the line, if any is met, skip to the next line.
Is this something that sed would be able to do?