Suppose I have a configuration file that can be in one of two format below (short example, but basically the first format is a line that is too long that you have to use a line continuation character, while the second format is just simply a long line without the line continuation)
data1=x data2=y data3=z \
datakey
second format
data=1 data2=y data3=z datakey
I want to match the exact line data1=x data2=y data3=x datakey for both situation. Is there simple way of doing that?
I would use sed to create an output without the ending
\:Then you could grep it:
You can even do this all in sed:
UPDATE:
To explain above:
:beginsets a tag to which I can branch (goto) with thebcommand./\\$/{N;bbegin}if the current line ends with a\(/\\$/), append the next line to the buffer (N) and goto begin (bbegin).\, remove all the\and the line break (thes/\\n//g`).-noption tells sed no to print the line at the end of the script./your_pattern/pprints the line if it matchesyour_pattern.UPDATE2:
We could even do better and show the original lines of your file:
What this does is before removing the
\and the line break, it saves the data in the hold space (h) and if the line matches, it prints the data that was saved (gcopies the hold space to the pattern space that is printed).