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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 08:29 AM
adding a line to a file andy2000 Shell Programming and Scripting 2 03-26-2007 08:44 AM
adding spaces to a line mgirinath Shell Programming and Scripting 4 03-23-2007 12:38 PM
Stop awk adding a new line TobyR Shell Programming and Scripting 1 06-18-2006 11:30 AM
adding line terminator thanuman UNIX for Dummies Questions & Answers 1 02-24-2005 07:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2007
sovixi sovixi is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 1
sed - adding new line

I want to use sed to look for spaces in text and when find one move the next word to the next line.

I used:

sed 's/ /\n/g' out > new

However when there is more than one space between two words it adds more lines between them. And I just want the words to be one under another. How can I change that?

Thanks

I find out how to do this:

sed '/^$/d'

However when I'm using emacs and put this two commands in one line they don't want to work:

#! /bin/bash
sed 's/ /\n/g' | sed '/^$/d' out > new

What I'm doing wrong???

Last edited by sovixi; 10-08-2007 at 07:56 PM..
  #2 (permalink)  
Old 10-09-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
Use awk:

Code:
% cat file
word word  word    word
word     word 
     word
% awk '$1=$1' RS= OFS="\n" file
word
word
word
word
word
word
word
On Solaris use nawk or /usr/bin/awk .

Or with tr:
Code:
% tr -s ' ' '\n' <file
word
word
word
word
word
word
word

Last edited by radoulov; 10-09-2007 at 06:11 AM..
  #3 (permalink)  
Old 10-09-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,932
awk '{ for (i=1; i<=NF; i++) { print $i } }' filename
Sponsored Links
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 07:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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