The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete text from line starting pattern1 up to line before pattern2? repudi8or Shell Programming and Scripting 5 04-15-2008 06:25 PM
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 10:15 AM
Changing Line Number of a File ilak1008 Shell Programming and Scripting 17 05-21-2007 10:05 PM
Changing userID and Changing group and GID deal732 Shell Programming and Scripting 2 04-18-2007 07:09 AM
Remove header(first line) and trailer(last line) in ANY given file madhunk Shell Programming and Scripting 2 03-13-2006 11:36 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: May 2008
Posts: 39
Stumble this Post!
changing colomn to the line

I have a file which has only one colomn of numbers,ex:
122
173
292
400
979
2152
2339
2376
2387
2446
2450

What ksh / unix command should I use to create a file in which those numbers will be in one line,like this
122 173 292 400 979 .... etc

Thanks a lot for help
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-10-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,795
Stumble this Post!
One way -
Code:
awk '{printf("%s ", $0) } END {print ""}  ' oldfile > newfile
Reply With Quote
  #3 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: May 2008
Posts: 39
Stumble this Post!
Thanks a lot for help
Reply With Quote
  #4 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Apr 2008
Location: Bangalore
Posts: 120
Stumble this Post!
One more way

cat filename | tr "\n" " "

Thanks
Penchal
Reply With Quote
  #5 (permalink)  
Old 06-10-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
Quote:
Originally Posted by penchal_boddu View Post
One more way

cat filename | tr "\n" " "

Thanks
Penchal
why exactly do you need 'cat' here?
Reply With Quote
  #6 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Mar 2008
Posts: 17
Stumble this Post!
You can even do that using...

echo `cat filename`

It should work.

Amit
Reply With Quote
  #7 (permalink)  
Old 06-10-2008
Registered User
 

Join Date: Apr 2008
Location: Bangalore
Posts: 120
Stumble this Post!
Hi Vgresh,

tr works on strings that input is being provided by cat command.

I dont think i can write like tr "\n" " " filename.

If iam wrong, Please correct me.

Thanks
Penchal
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0