/ Published in: Awk
For use in bash script. First two lines are an example of usage. This is one of several solutions to this problem. Works well for cleaning database output. Takes a regex and two files as arguments - first one is raw db output - second is merged output.This assumes unwanted line breaks. You can also get the same results working with the newline characters -- will post that one as well. The --re-interval option is only necessary if you want to enable regex interval operators like {n} or {n,m} ....etc. If using a current version of GNU Awk, might as well leave it in there.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
REGEX="/^[^|]/" func_merge_lines "$REGEX" $TMP1 $TMP2 function func_merge_lines { awk --re-interval "NR==1 \ { s=\$0;next } \ "$1"{ s=s\$0;next } \ { print s;s=\$0 } END {if(s)print s}" $2 > $3 # merge lines. # Looks for lines not starting with pipe # then merges line below to end. }