awk delete newline after other replacements


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk delete newline after other replacements
# 1  
Old 02-08-2013
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.
# 2  
Old 02-08-2013
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.
# 3  
Old 02-09-2013
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
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().
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Entering a newline into a header in awk

I want to create a header with awk like this: gawk 'BEGIN {print "List of Events"} Desired output: List of Events Tennis Baseball But I am at a loss on how to do this. I can make a list like this: List of Events Tennis Baseball But I can't get a space to appear. I have... (4 Replies)
Discussion started by: newbie2010
4 Replies

2. Shell Programming and Scripting

awk: printing newline with last column

I was trying to simplify this from what I'm actually doing, but I started getting even more confused so I gave up. Here is the content of my input file: Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,7th Period,Davis,Lucille When I do this: ... (3 Replies)
Discussion started by: nextyoyoma
3 Replies

3. UNIX for Dummies Questions & Answers

Selective Replacements: Using sed or awk to replace letters with numbers in a very specific way

Hello all. I am a beginner UNIX user who is using UNIX to work on a bioinformatics project for my university. I have a bit of a complicated issue in trying to use sed (or awk) to "find and replace" bases (letters) in a genetics data spreadsheet (converted to a text file, can be either... (3 Replies)
Discussion started by: Mince
3 Replies

4. Shell Programming and Scripting

How to delete newline with perl

input: donkey monkey dance drink output should be: donkey monkey (8 Replies)
Discussion started by: cola
8 Replies

5. Shell Programming and Scripting

awk puts newline between fields

I have a='123, abc, def, ghi' var1=`echo $a | awk -F", " '{print RS $1}'` echo "something: $var1" which outputs something 123 how can I tell awk not to put a newline between fields? I want it to output: something: 123 (4 Replies)
Discussion started by: unclecameron
4 Replies

6. Shell Programming and Scripting

sed/awk remove newline

Hi, I have input file contains sql queries i need to eliminate newlines from it. when i open it vi text editor and runs :%s/'\n/'/g it provides required result. but when i run sed command from shell prompt it doesn't impact outfile is still same as inputfile. shell] sed -e... (6 Replies)
Discussion started by: mirfan
6 Replies

7. Shell Programming and Scripting

using awk removing newline and specific position

Hello Friends, Input File looks as follows: >FASTA Header1 line1 line2 line3 linen >FASTA Header2 Line1 Line2 linen >FASTA Header3 and so on ....... Output: Want something as: >FASTA Header1 line1line2line3linen >FASTA Header2 (5 Replies)
Discussion started by: Deep9000
5 Replies

8. UNIX for Dummies Questions & Answers

Delete the line started with nondigit or newline character

i want to delete the line which is not started with numeric in vim. vim temp.txt Volume in drive D is DATA Volume Serial Number is 8C52-2055 Directory of D:\data\notes 02/16/2010 03:09 PM <DIR> . 02/16/2010 03:09 PM <DIR> .. 09/11/1999 03:03 AM ... (5 Replies)
Discussion started by: Manabhanjan
5 Replies

9. UNIX for Dummies Questions & Answers

delete newline character between html tags

Hi, I have learned some of the Unix commands a way back and not sure of how to code them when needed in certain way, especially sed command. Here is my situation. I have an xml file with several tags. most of the tags start on the same line and end on the same line. However, data for some tags... (8 Replies)
Discussion started by: girish312
8 Replies

10. Shell Programming and Scripting

Awk error for joining records with CR/newline

Is there any way to remove carriage retuns between the records? These carriage returns are created in an excel cell by using Alt+enter, this is similar to new line... We have input records separated by TABS and have carriage returns as below: 123 456 789 ABC "1952.00" 678 "abcdef ghik... (5 Replies)
Discussion started by: acheepi
5 Replies
Login or Register to Ask a Question