Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have several ini files that I need to edit
some have multiple file names that need to be added and some only have one name.
the format is very specific in order for the program to work-- this is where my problem lies.If a file has only one name -- then one name is listed with no comma at the end.
If a file has multiple names-- then each name is listed with a comma at the end except for the last name.example:
xxCount=1
xlCount=3
COUNTRY1='xx xl"DIRS="$COUNTRY1"
for i in $DIRS
do
cd $PATH/$i
eval dirCount=\$${i}Count
echo $dirCountx=1
While [ $x -le $dirCount ]
do
if [ $x -eq 1 ]
then outText="${i}_${x}.txt,"
else outText=$outText\n${i}_${x}.txt,"
fi
x=`expr "$x" + 1`
doneed - ${i}_test.txt << end-of-script
/data.txt/c
`echo $GEF$outText`
.
w
end-of-script
what I am getting is this
in xx_test.txt I am getting this
xx_1.txt,
do not want a comma since it is only one file
should be xx_1.txtin xl_test.txt I am getting this
xl_1.txt,
xl_2.txt,
xl_3.txt,do not want a comma after xl_3.txt since this is the last file
should be xl_1.txt,
xl_2.txt,
xl_3.txt
what am I doing wrong with the commas-- only need them if there are multiples but the last one needs not to have a comma.thanks
using unix or linux

Try changing your if statement as follows:
if [ $x -eq 1 ]
then outText="${i}_${x}.txt"
else outText="$outText,\n${i}_${x}.txt"
fiThat is, remove the comma that was at the end of the outText=... statement in the 'then' clause, and move the comma in the 'else' clause from the end of the line to right before the linefeed (\n).

![]() |
UNIX proceses stopped by ...
|
Cron jobs of other users
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |