Hi
I have a file sequential way i.e. written in contineous mode and the Record Seperator is AM from which the record is seperated .Now to process I have to make line sequential,and more over record length is not same it varies as per the input address,
AM1234563 John Murray 24 Old streeet old way Chicago AM451235 Lawrance Kaylep new roan ridge road kansas city AM87954 Ashly Woods kalgurah park lane jersy city NJ AM96245 Linus Macanzeestreet river side lane Detroit AM753125 Thomas Alva Kopasli way Las vagas
Output wanted in this format
AM1234563 John Murray 24 Old streeet old way Chicago
AM451235 Lawrance Kaylep new roan ridge road kansas city
AM87954 Ashly Woods kalgurah park lane jersy city NJ
AM96245 Linus Macanzee street river side lane Detroit
AM753125 Thomas Alva Kopasli way Las vagas
Can anyone guide ??
Thanks in advance
Vakharia M J
try:
awk 'NR>1{print "AM"$0}' RS="AM" urfile
1 Like
Dear Scrutinizer and Yinyuemi,
Thanks a lot both of you for your code and fot this I was just :wall: since
two days, and you made it so simple But once again just a bit to share more
Had it been more than one filed seperator can I use this with little correction
like
awk 'NR>1{print "AM"$0}' RS=["AM","yAM"] urfile
I gave a try but did not give correct result,
Thanks once again for your code,
Vakharia M J
Hi Vakharia, you're welcome. In regular awks, RS can only be one character. If more characters are used, the leftmost character gets used. GNU awk (gawk) allows RS to be a regular expression. Try:
awk '{gsub(/y?AM/,"\n&")}1' file
or
awk '{gsub(/y?AM/,"\nAM")}1' file
or
awk '{gsub(/yAM|AM/,"\nAM")}1' file
or
gawk 'NR>1{print "AM"$0}' RS="y?AM" file
if you want the y removed.
Alternatively, with sed..
sed 's/y\{0,1\}AM/\n&/g' file
or just:
sed 's/y\{0,1\}AM/\nAM/g' file
if you want the y removed..
1 Like
Scrutinizer ,
Oh so kind of you and I have just corrected the code to suit my requirement .
But good to suggest the code on which I could go further.
Have great week end. yinyuemi you too.
Vakharia M J