Hi,
I need unix shell script that can read the first column of a text file and matching each column string is a folder and i need to read files from the specified folder e.g
Main.txt has
Mike 690
Jhon 346
i need to read Mike first then open up the files in folder Mike in the same directory.Similarly, for Jhon there exists a folder called Jhon and i need to read files from the jhon folder.
Can anyone provide me with the script
Thanks.
use a forloop and as the list do a forward tick and then use awk to get the first field from the file.
now that you have your list of directories i assume you would want to enter that directory and get a list fo files (another for loop) and do your processeing on them.
Hmmm..... sounds like it could be a homework question, but the benefit of the doubt goes to you.....
Assuming the list is in Main.txt and the numbers are of no significance:
#!/bin/sh
while read line
do
_file=`echo $line | awk '{print $1}'`
if [ -d $_file ]; then
ls -l $_file
# or whatever else you wanna do
else
echo "$_file is not a directory (or does not exist)"
fi
done < Main.txt
exit 0
If this is a homework question, slap me with a wet fish for giving you the answer.
Peace,
ZB
http://www.zazzybob.com