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
How to change the file modification time of a file on nfs mount point deepthi.s UNIX for Dummies Questions & Answers 6 07-11-2008 07:11 AM
How to change the file name rp1982 UNIX for Dummies Questions & Answers 2 11-30-2007 12:49 AM
Help to change value from a file. GCTEII Shell Programming and Scripting 15 03-07-2006 11:54 AM
How to change this file with SED? bejgirl Shell Programming and Scripting 4 01-03-2006 09:23 AM
Help with multiple file rename - change case of part of file name steve7 UNIX for Dummies Questions & Answers 7 06-30-2005 01:41 PM

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 02-09-2009
maya maya is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 6
how to change my file

hi everybody!

I have a file (txt) that contains many rows:

abc 22
cde 32
KKK 11

I want to change the file , and then print the contents of txt file (see below):

abc 22 cde 32 kkk 11


Any help is most appreciated.
Thanks

Last edited by maya; 02-09-2009 at 03:14 AM..
  #2 (permalink)  
Old 02-09-2009
ranjithpr ranjithpr is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 157
You can change the new lines in your file with space with following command

tr "\n" " " < file
  #3 (permalink)  
Old 02-09-2009
ddreggors ddreggors is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 91
Do mean just edit the file?

Command line or GUI (Gnome/KDE/other)?
  #4 (permalink)  
Old 02-09-2009
ranjeetmenon ranjeetmenon is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 4
If your contents are in file "a", and your new file is "b":

tr "\n" " " <a > b
  #5 (permalink)  
Old 02-09-2009
maya maya is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 6
Thanks for the explaination.
  #6 (permalink)  
Old 02-09-2009
timontt timontt is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 44
cool, i like the tr way... Thanks!

Below is a another way...
for i in `cat filename`;do
printf "$i " >> newfile
done
  #7 (permalink)  
Old 02-09-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,293
Quote:
Originally Posted by timontt View Post
cool, i like the tr way... Thanks!

Below is a another way...
for i in `cat filename`;do
printf "$i " >> newfile
done
Avoid the useless use of cat:

Code:
while read i
do
  printf "$i " >> newfile
done < filename
Regards
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 09:10 PM.


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