Unix/Linux Go Back    

Substitute newline with tab at designated field separator

Shell Programming and Scripting

Kindly Note - This is a Single User Post by Forum Member yifangt Regarding:
Substitute newline with tab at designated field separator.
Please Follow The Primary Link Above to View the Full Discussion.

Old Unix and Linux 04-02-2013   -   Original Discussion by yifangt
yifangt's Unix or Linux Image
yifangt yifangt is offline VIP Member  
Join Date: Sep 2009
Last Activity: 21 March 2018, 6:45 PM EDT
Location: Saskatchewan, Canada
Posts: 522
Thanks: 338
Thanked 8 Times in 8 Posts
Thanks Hanson!
What's in my mind with tr is: replace "\n" with "\t" if the rows not connected by "\n" and "@" (That's why I wrote, !\n@, which is not a correct syntax, obviously! ). It seems I have to forget this strategy!
Now the "N" is clear in the command. Could you explain what the "1" does? Similar script I saw with awk http://wiki.ljackson.us/Awk_Command.

# if a line ends with a backslash, append the next line to it 
# (fails if there are multiple lines ending with backslash...)
 awk '/pattern/ {sub(/\n/,"\t"); getline t; print $0 t; next}; 1' infile

Thanks again!

Last edited by yifangt; 04-02-2013 at 11:48 PM.. Reason: improve wording