Bash/sed: Concat multiple line plus eat up leading spaces for sublines -


i want parse makefiles containing lines these:

files=file1.c \       file2.c \       file3.c \ 

now want parse beast result this:

files=file1.c file2.c file3.c 

means should concat line 1 line , eat leading spaces. managed concat lines using sed call:

sed -e ':loop;/\\$/n;s/\\\n/ /;t loop' 

which results in

files=file1.c      file2.c      file3.c 

but yet did not manage eat leading spaces line 2 , line 3 of example.

thanks help,

roland

btw: using gnu sed version 4.1.5 here.

this seems work me:

sed -e ':loop;/\\$/n;s/\\\n/ /;t loop' -e 's/ \+/ /g' < makefile 

thanks dennis williamson pointing out don't need -r if escape + \. notes doesn't work when last character before end of file \. however, that's unlikely in real example, since there's no point in doing line continuation if there's nothing afterwards. e.g. works fine with:

files=file1.c \       file2.c \       file3.c 

... instead.

i've tested gnu sed 4.2.1 - i'm afraid don't have earlier version hand.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -