writing a script..new to this

November 12, 2010 at 07:27:27
Specs: unix
help writing a unix script..new to writing scripts

i have a file with names in it lets call it a testfile.txt...
1. i want to make sure all the names are lowercase...so i was going to do this..
tr '[A-Z]' '[a-z]' testfile.txt > lowerfile.txt

2. i wante to add a *, to the front of each name and a ,*,* to the end of each name and i was able to do this by this line command..
cat lowerfile.txt | xargs -iz eacho "*," "Z" ",*,*" > newfile.out

3. wanted to name newfile.out to test(next number available).out...like test1.out..test2.out what ever the next available number is ...and echo the output file is ......out

See More: writing a script..new to this

Report •

December 15, 2010 at 23:33:38
Creating a file to test:

# cat > testfile.txt

Converting upper to lower:

# cat testfile.txt | tr -s '[:upper:]' '[:lower:]' > lowerfile.txt

Adding * to the front and ,*,* to the end and create test.. out file

# while read line
echo "* $line ,*,*" >> newfile.out
done < lowerfile.txt

last_file_number=`ls -1 test*.out | sort | tail -1 | cut -c 5`
next_file_number=` expr $last_file_number + 1 `
mv newfile.out test${next_file_number}.out

exit 0

Hope it helped.

Report •

December 16, 2010 at 03:08:37
I believe that nobody offered a solution to this problem because prepending an * to a file name is a rather silly thing to do, particularly in Unix.

Report •
Related Solutions

Ask Question