|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
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 | ||
|
![]() |
| Tags |
| awk, gsub, newline, replacements |
| Thread Tools | Search this Thread |
| 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 |
|
|