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.
:cool:

  1. If you have no privileges to write files you can't do this anyway.
tr -s '\n' ',' < oldfile > tmpfile; mv tmpfile oldfile

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 ?

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.

cat <oldfile> | tr -s "
" "," > <oldfile>

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 !!!
:rolleyes:

Here's another way to do it:

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

Or...

paste -s -d , < file1 > file2 && mv file2 file1

Hi,
Thanks you all.
"System shock" response was perfctly to me.
Thanks Again !

To remove it:

$cat > remove
#! /bin/bash
coma=IFS
IFS=","
for i in`cat file.txt`
do
if [ `echo $i` = <chain you like to delete> ]
then
echo $i >> file2.txt
fi
done
IFS=$coma
unset coma

Remember that
OUTPUT file.txt
'/ttt/aaa','/ttt/bbb','/ttt/ccc','/ttt/ddd','/ttt/eee',

OUTPUT file2.txt
'/ttt/aaa'
'/ttt/bbb'
'/ttt/ccc'
'/ttt/ddd'
'/ttt/eee'

Bye