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-03-2013   -   Original Discussion by yifangt
yifangt's Unix or Linux Image
yifangt yifangt is offline VIP Member  
UNIX.COM VIP Member
 
Join Date: Sep 2009
Last Activity: 15 December 2017, 4:22 PM EST
Location: Saskatchewan, Canada
Posts: 516
Thanks: 332
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.

Code:
# 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-03-2013 at 12:48 AM.. Reason: improve wording