I am trying to merge two lines to one based on some matching condition.
The file is as follows:
Matches filter:
'request ', timestamp, <HTTPFlow
request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow
request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow
request=<GET:
I want to merge the line ending with <HTTPFlow with the next line request. The expected output is:
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Thanks.
Hello Jamie_123,
Following may help you in same.
awk '(NR%2==0){A=$0;getline;print A OFS $0;NR++;next};{print}' Input_file
Output will be as follows.
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Thanks,
R. Singh
1 Like
RudiC
3
Try also
awk '/<HTTPFlow$/ {getline X; $0 = $0 X} 1' file
1 Like
Aia
4
perl -pe 's/(<HTTPFlow)\n/$1 /' jamie.file
---------- Post updated at 09:35 AM ---------- Previous update was at 08:23 AM ----------
awk '/<HTTPFlow$/ {printf $0;next}1' jamie.file
1 Like
Some more:
awk '!/<HTTPFlow$/{$0=$0 RS} 1' ORS= file
awk '1;!/<HTTPFlow$/{print RS}' ORS= file
awk '{ORS=/<HTTPFlow$/?x:RS}1' file
printf $0
will do terrible things if $0 has %
signs!
Correct is printf "%s",$0
--
A sed solution:
sed '/<HTTPFlow$/ {$!N; s/\n//;}' file
Hello Scrutinizer,
For code:
awk '{ORS=/<HTTPFlow$/?x:FS}1' Input_file
It will give output as follows.
Matches filter: 'request ', timestamp, <HTTPFlow request=<GET: Matches filter: 'request ', timestamp, <HTTPFlow request=<GET: Matches filter: 'request ', timestamp, <HTTPFlow request=<GET:
We can change a bit to it to as follows:
awk '{ORS=/<HTTPFlow$/?FS:"\n"}1' Input_file
Output will be as follows then.
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Matches filter:
'request ', timestamp, <HTTPFlow request=<GET:
Thanks,
R. Singh
1 Like
Certainly a typo
awk '{ORS=/<HTTPFlow$/?x:RS}1' file
x is "", while FS adds another space.
1 Like
Indeed Ravinder and MadeInFermany, that should be RS, not FS. Corrected it in my post...