Computing.Net > Forums > Unix > unix for editing

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

unix for editing

Reply to Message Icon

Name: htnkd
Date: November 8, 2004 at 09:45:41 Pacific
OS: xp
CPU/Ram: 600
Comment:

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 $dirCount

x=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`
done

ed - ${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.txt

in 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




Sponsored Link
Ads by Google

Response Number 1
Name: chrysalis63
Date: November 8, 2004 at 14:19:02 Pacific
Reply:

Try changing your if statement as follows:

if [ $x -eq 1 ]
then outText="${i}_${x}.txt"
else outText="$outText,\n${i}_${x}.txt"
fi

That 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).


0
Reply to Message Icon

Related Posts

See More


UNIX proceses stopped by ... Cron jobs of other users



Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: unix for editing

unix for database (add, update) www.computing.net/answers/unix/unix-for-database-add-update/4978.html

help redoing unix script student db www.computing.net/answers/unix/help-redoing-unix-script-student-db/5151.html

Unix for loop www.computing.net/answers/unix/unix-for-loop/3717.html