Computing.Net > Forums > Unix > passing files as argument

passing files as argument

Reply to Message Icon

Original Message
Name: sivakarthik
Date: September 29, 2005 at 10:21:23 Pacific
Subject: passing files as argument
OS: Unix
CPU/Ram: 512
Comment:

Hi,
I want to excute a shell script by passing a CSV file as argument, where the file name will be based on the file that is been placed in a particular directory.

Ex: cleaner.sh GSM20050609.csv

the argument file will be the one in the directory. How to read the file name and pass it.

Thanks
Siva

Hi,
I'm trying to replace a column in a comma seperated file with a column in another file using sed/awk. Can anyone help me.

Thanks
Siva



Report Offensive Message For Removal

Response Number 1
Name: Jim Boothe
Date: September 29, 2005 at 11:35:11 Pacific
Subject: passing files as argument
Reply: (edit)

if [ $# -ne 1 ] ; then
   echo '\nUsage: cleaner.sh <filename>\n'
   exit 1
fi

dir=/home/particular
fname=$1

if [ ! -r $dir/$fname ] ; then
   echo "$fname does not exist in $dir"
   echo "   or I have no read access"
   exit 1
fi

echo "Now processing $dir/$1 ..."


Report Offensive Follow Up For Removal

Response Number 2
Name: sivakarthik
Date: September 30, 2005 at 01:58:06 Pacific
Subject: passing files as argument
Reply: (edit)

Jim,
Think my question is not clear, let me put it in other way..
In /home/files I have 2 files GMS.txt and AMS.txt
I've my script /home/scripts/cleaner.sh

Now I want to pass all the files in /home/files to cleaner.sh as argument one by one.
like cleaner.sh GMS.txt
cleaner.sh AMS.txt
I want a script which will get files from /home/files directory and pass it to cleaner.sh as argument.
Can you help me.

Thanks
Siva

Hi,
I'm trying to replace a column in a comma seperated file with a column in another file using sed/awk. Can anyone help me.

Thanks
Siva



Report Offensive Follow Up For Removal

Response Number 3
Name: Jim Boothe
Date: September 30, 2005 at 06:12:03 Pacific
Subject: passing files as argument
Reply: (edit)

Sure, here's a couple of different ways:


find /home/files -exec c /home/scripts/cleaner.sh {} \;


or

for fname in $(ls /home/files)
do
/home/scripts/cleaner.sh $fname
done


On the find command approach, you can add additional filters to the find command, such as:

regular files only (ignore directories etc)
modify date filter
file size filter
file ownership
etc


Report Offensive Follow Up For Removal

Response Number 4
Name: sivakarthik
Date: September 30, 2005 at 10:17:27 Pacific
Subject: passing files as argument
Reply: (edit)

Jim,
Yeah....it works great.

Thanks
Siva

Hi,
I'm trying to replace a column in a comma seperated file with a column in another file using sed/awk. Can anyone help me.

Thanks
Siva



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: passing files as argument

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software