regex - awk concatenate next lines when matching -
i using awk analyze text file , concatenate lines matching regex following line. using following command:
awk '/^ [0-9]/{printf $0 ;next;}1' *filename*
when test prompt works expected when put same command in bash script output same input file.
any idea on why should not work in bash script?
update
here's complete script:
#!/bin/bash # file in $( ls *.raw ) awk '/^ [0-9]/{printf $0 ;next;}1' file > temp done
i tried using awk '/pattern/{printf "%s",$0;next}1' file
suggested @kent add %s @ beginning of file.
solved
i modified command concatenate matching line 2 following lines using getline follows:
(awk '/^ [0-9]/{l1=$0;getline;l2=(l1 $0);getline; print l2 $0}' < input_file) > output_file
i modified command concatenate matching line 2 following lines using getline follows:
(awk '/^ [0-9]/{l1=$0;getline;l2=(l1 $0);getline; print l2 $0}' < input_file) > output_file
Comments
Post a Comment