To Make Sure All Names Are Lowercase

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 wanted 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. I 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 

Solution:

Creating a file to test:

# cat > testfile.txt
Name1
NaME2
NamE3
nAmE4

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
do
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
 

Note:

Prepending an * to a file name is a rather silly thing to do, particularly in Unix.

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.