awk delete newline after other replacements | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

awk delete newline after other replacements

Shell Programming and Scripting


Tags
awk, gsub, newline, replacements

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-08-2013
shivacoder shivacoder is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 9 February 2013, 11:12 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
awk delete newline after other replacements

Dear All,

could you please help me to remove \n characters after all other replacements have been done as in the code below:


Code:
{

#remove punctuation and starting whitespaces
  gsub("[[:punct:]]"," ");
  $1=$1;
}
{
#print lines containing 'whatever'
  if ($1=="whatever")
  {print}
#print lines longer then 150 chars 
 else if (length($0) > 150)
  {print}
}
{
#does not work - need to get rid of all \n and then replace 'whatever' with \n
gsub("[\n]"," ");
{print}
}

Thank you for your great expertise.
Sponsored Links
    #2  
Old 02-08-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 20 August 2014, 3:47 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,398
Thanks: 8
Thanked 536 Times in 515 Posts
You might have hit the side of the box, this is a line oriented tool. Do you want to merge some lines or remove all linefeeds? Command "tr -d '\12'" removes all linefeeds.
Sponsored Links
    #3  
Old 02-09-2013
shivacoder shivacoder is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 9 February 2013, 11:12 AM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you. I wanted to go AWK only and figured out to put -ORS " " to remove newline chars from output. This is a partial solution, thought.
    #4  
Old 02-11-2013
DGPickett DGPickett is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 20 August 2014, 3:47 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,398
Thanks: 8
Thanked 536 Times in 515 Posts
Both awk and sed can read the next line or additional lines into the buffer so you can evaluate if you want to preserve the linfeed between those lines. I once wrote a sed to take whole pages and turn them into lines by reversing the new line and form feed. Then another sed could turn the pages into insert statements. Finally, I turned the form feeds back into new lines, so the displayed page from the db would be correct. The DB allowed 32k char().
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Selective Replacements: Using sed or awk to replace letters with numbers in a very specific way Mince UNIX for Dummies Questions & Answers 3 07-03-2012 12:27 PM
Conditional replacements kewk Shell Programming and Scripting 6 04-28-2011 10:50 PM
How to delete newline with perl cola Shell Programming and Scripting 8 10-15-2010 01:44 AM
Delete the line started with nondigit or newline character Manabhanjan UNIX for Dummies Questions & Answers 5 02-17-2010 10:04 AM
delete newline character between html tags girish312 UNIX for Dummies Questions & Answers 8 02-29-2008 04:24 AM



All times are GMT -4. The time now is 10:22 PM.