The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh scripting help praveenbvarrier Shell Programming and Scripting 1 04-15-2008 10:19 AM
Scripting Help! liezer Shell Programming and Scripting 7 09-15-2006 03:52 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 07:58 PM
HELP! Need HELP scripting! adawg1283 Shell Programming and Scripting 7 09-29-2004 03:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-01-2008
Muki101 Muki101 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 9
Thanks Franklin52, the code you gave works just fine, except there is one problem. I want it to make a new paragraph when tab is used as well.

So if the input file is:

Code:
First line of the second paragraph.
Second line of the second paragraph.
     Third as well.
The output is:

Code:
First line of the second paragraph. Second line of the second paragraph.
     
Third as well.
I tried adding "\t" to RS in addition to the "\n\n". Is that the right thing to do anyway? Agaiss it isn't, cause if I replaced the "\n\n" with "\t" then it should have made a new paragraph to my mind, but it didn't. So any further assistance is greatly appreciated.

Thanks in advance!

Last edited by Muki101; 12-01-2008 at 06:59 AM..
  #2 (permalink)  
Old 12-01-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,300
You can left the awk code unaltered. Translate the tabs to newlines with tr and pipe the output to the awk command:

Code:
tr '\t' '\n' < file | awk 'BEGIN {RS=ORS="\n\n"} $1=$1'
This is what I get:

Code:
$ cat file
    The first line.
Second line.

First line of the second paragraph.
Second line of the second paragraph.
    Third as well.
$
$ tr '\t' '\n' < file | awk 'BEGIN {RS=ORS="\n\n"} $1=$1'
The first line. Second line.

First line of the second paragraph. Second line of the second paragraph.

Third as well
Regards
  #3 (permalink)  
Old 12-02-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,082
Hi i think perl is a little bit easier than awk

Code:
$/="\n\n";
open FH,"<a.txt";
while(<FH>){
	tr/\n//d;
	print $_,"\n";
}
  #4 (permalink)  
Old 12-02-2008
Muki101 Muki101 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 9
Thanks alot Franklin52! Works just fine

But I was wondering whether it`s possible to do it entirely int AWK?
Closed Thread

Bookmarks

Tags
sed delete line

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0