Wednesday, December 26, 2007

Unix - List File & Parse File name

Requirement:

Find list of files in current directory and parse the file names to decipher which program to execute

#!/usr/bin/ksh

echo 'Nambi'

#To find files with "text" in all sub directories from current
#find . -type f -name "text" -print| while read obj
#To find ALL files in all sub directories from current
#find . -type f -print| while read obj

#Just files in current directory
ls -1 | while read fname
do
echo 'File name:'$fname
#Parse file name to get specific output
#echo $fname | cut -c-3
l=`echo $fname | cut -c2-4`
echo $l

done

echo 'End'

No comments: