Kanja
May 13, 2015, 11:24pm
1
I do have a text file with multiple lines on it. I want to put the lines of text into a single line where ever there is ";"
for example
ert, ryt, yvig,
fgr;
rtyu, hjk, uio,
hyu,
hjo;
ghj, tyu, gho,
hjp, jklo,
kol;
The resultant file I would like to have is
ert, ryt, yvig, fgr;
rtyu, hjk, uio, hyu,hjo;
ghj, tyu, gho, hjp, jklo, kol;
Please let me know how to do this either in awk or sed
I don't see any obvious way to guess when you want spaces added to the end of a line when it is joined to an earlier line. If you are willing to always add a space when a line is joined, this seems to work:
awk '
! /;/ {printf("%s ", $0)
next
}
1' file
which produces the output:
ert, ryt, yvig, fgr;
rtyu, hjk, uio, hyu, hjo;
ghj, tyu, gho, hjp, jklo, kol;
instead of:
ert, ryt, yvig, fgr;
rtyu, hjk, uio, hyu,hjo;
ghj, tyu, gho, hjp, jklo, kol;
as you requested.
RudiC
May 14, 2015, 7:42am
3
sed
version:
sed -n ':a /;$/!N;s/\n//g;ta;p' file
ert, ryt, yvig,fgr;
rtyu, hjk, uio,hyu,hjo;
ghj, tyu, gho,hjp, jklo,kol;