Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using grep, treating two lines as one?

Tags:

linux

grep

bash

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?

like image 894
tim tran Avatar asked Feb 18 '26 21:02

tim tran


1 Answers

read interprets \ as the line continuation character:

while read line ; do
    if [[ $line == 'data=1 data2=y data3=z datakey' ]] ; then
        echo "$line"
    fi
done
like image 75
choroba Avatar answered Feb 21 '26 11:02

choroba