Revision: 29951
Updated Code
at August 7, 2010 10:20 by bubnoff
Updated Code
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. }
Revision: 29950
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 5, 2010 10:17 by bubnoff
Initial Code
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 starting with pipe # then merges line below to end. }
Initial URL
Initial Description
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.
Initial Title
Merge lines with Awk
Initial Tags
Bash
Initial Language
Awk