yoavbe
June 23, 2006, 2:48pm
1
Hi ,
I have a text file look like the following:
'/ttt/aaa'
'/ttt/bbb'
'/ttt/ccc'
'/ttt/ddd'
'/ttt/eee'
I need to rebuild its content and make it look like :
'/ttt/aaa','/ttt/bbb','/ttt/ccc','/ttt/ddd','/ttt/eee'
I cant create a new file. the changes need to be done inside the same file
can one suggest how to do it ?
Thanks.
If you have no privileges to write files you can't do this anyway.
tr -s '\n' ',' < oldfile > tmpfile; mv tmpfile oldfile
yoavbe
June 23, 2006, 4:16pm
3
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 ?
reborg
June 23, 2006, 5:01pm
4
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>
yoavbe
June 24, 2006, 12:53am
6
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:
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 !!!
: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
Ygor
June 25, 2006, 6:34am
8
Or...
paste -s -d , < file1 > file2 && mv file2 file1
yoavbe
June 25, 2006, 12:55pm
9
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