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 read the column and print the values under that column gemini106 Shell Programming and Scripting 6 03-28-2008 07:05 AM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 09:57 AM
extracting/copy a column into a new column folashandy UNIX for Advanced & Expert Users 1 02-21-2008 01:24 PM
How to pass one parameter from one column to another column in AWK prasanta jena Shell Programming and Scripting 1 07-30-2007 06:08 AM
Replace 10th column with a new column--- Terriblly hurry ahmedwaseem2000 Shell Programming and Scripting 2 09-06-2005 01:10 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 06-23-2006
yoavbe yoavbe is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 42
from column to row

Hi ,
I have a text file look like the following:
'/ttt/aaa'
'/ttt/bbb'
'/ttt/ccc'
'/ttt/ddd'
'/ttt/eee'

1. I need to rebuild its content and make it look like :
'/ttt/aaa','/ttt/bbb','/ttt/ccc','/ttt/ddd','/ttt/eee'
2. I cant create a new file. the changes need to be done inside the same file
can one suggest how to do it ?

Thanks.
  #2 (permalink)  
Old 06-23-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
2. If you have no privileges to write files you can't do this anyway.
1.
Code:
tr -s '\n' ',' < oldfile > tmpfile; mv tmpfile oldfile
  #3 (permalink)  
Old 06-23-2006
yoavbe yoavbe is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 42
Hi ,
I tried to to implement you suggestion, as follow:

ListOfFilesToImport="/${SOURCE_ORACLE_SID}/TTS/ListOfFilesToImport.lst"
tr -s '\n' ',' $ListOfFilesToImport $ListOfFilesToImport.tmp; mv $ListOfFilesToImport.tmp $ListOfFilesToImport

But got the follwoing error:
Usage: tr [ -c | -cds | -cs | -ds | -s ] [-A] String1 String2
tr [ -cd | -cs | -d | -s ] [-A] String1
mv: /tsdwh/TTS/ListOfFilesToImport.lst.tmp: cannot access: No such file or directory

Any Suggesion ?
  #4 (permalink)  
Old 06-23-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
add the < and > as Jim poosted, they were part of the code, not indicating the the filename should be adjusted.

< file is redirecting the contents of the named file to stdin of tr
> is redirecting stdout from tr to the second named file.
  #5 (permalink)  
Old 06-23-2006
Doc_RuNNeR Doc_RuNNeR is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 17
cat <oldfile> | tr -s "
" "," > <oldfile>
  #6 (permalink)  
Old 06-24-2006
yoavbe yoavbe is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 42
Hi All,

Jim suggetsion: tr -s '\n' ',' < oldfile > tmpfile is almost perfect.
Its add an extra ',' at the end of the file:
'/ttt/aaa','/ttt/bbb','/ttt/ccc','/ttt/ddd','/ttt/eee',
Any suggestion how to remove it ?

Thank You !!!
  #7 (permalink)  
Old 06-24-2006
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
Quote:
Originally Posted by yoavbe
Hi All,

Jim suggetsion: tr -s '\n' ',' < oldfile > tmpfile is almost perfect.
Its add an extra ',' at the end of the file:
'/ttt/aaa','/ttt/bbb','/ttt/ccc','/ttt/ddd','/ttt/eee',
Any suggestion how to remove it ?

Thank You !!!
Here's another way to do it:

Code:
set -A FILE $(cat text.file)
echo ${FILE[@]} | sed 's/ /,/g' > file.txt
Without the pipe to sed, you'll get blank spaces in between values
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 10:29 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