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
help needed nnayagam Shell Programming and Scripting 2 03-07-2008 06:34 AM
Little help needed. Netghost AIX 5 08-10-2006 02:29 PM
Help needed dsravan Shell Programming and Scripting 2 07-20-2006 09:37 AM
awk help needed. cskumar Shell Programming and Scripting 0 07-20-2006 07:24 AM
Sed help needed stevefox Shell Programming and Scripting 5 12-05-2005 01:44 AM

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

Join Date: Sep 2007
Posts: 101
Help Needed in SED

Hi All ,

I have a input file which has set of lines like this ::

cat a.txt

unix1 djkdfkjdkkdfkdjfdfkjd 09191091 unix@unix.com <2008-23-07>
unix 2 dfdfdfdfdfdfdfdfdfd

unix3 dfldfljdflkjdfldfkljdfldjfl 0565606 unix1@unix.com <2008-10-09>
unix4 dfdlfndfldflnlffddfd

for some reason when i execute the SED command to bring it to single line , the code works partially

sed '=' a.txt | \
sed '{
N
s/\n/ /
}' a.txt > b.txt


the output is like this ::

unix1 djkdfkjdkkdfkdjfdfkjd 09191091 unix@unix.com <2008-23-07> unix 2 dfdfdf
dfdfdfdfdfdfd
unix3 dfldfljdflkjdfldfkljdfldjfl 0565606 unix1@unix.com <2008-10-09>
~

can you help me how to bring all those lines into single lines my output should be something like this :::


unix1 and unix2 shoule be in a single line
unix1 djkdfkjdkkdfkdjfdfkjd 09191091 unix@unix.com <2008-23-07> unix 2 dfdfdfdfdfdfdfdfdfd

and unix3 and unix4 should be in single line :::


unix3 dfldfljdflkjdfldfkljdfldjfl 0565606 unix1@unix.com <2008-10-09> unix4 dfdlfndfldflnlffddfd
  #2 (permalink)  
Old 04-05-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
If you don't have blanc line between the 2 lines this should work:

Code:
sed '{N; s/\n/ /}' a.txt > b.txt
Regards
  #3 (permalink)  
Old 04-05-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Code:
awk '/^$/ { print ""; next }
          { printf "%s ", $0 }
      END { print "" }' a.txt > b.txt
  #4 (permalink)  
Old 04-06-2008
raghav1982 raghav1982 is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 101
Thanks All for your Help!! Works perfectly!!
  #5 (permalink)  
Old 04-07-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
Code:
cat filename | paste - -
Closed Thread

Bookmarks

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 04:37 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