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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

passing files as argument

Reply to Message Icon

Name: sivakarthik
Date: September 29, 2005 at 10:21:23 Pacific
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




Sponsored Link
Ads by Google

Response Number 1
Name: Jim Boothe
Date: September 29, 2005 at 11:35:11 Pacific
Reply:

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 ..."


0

Response Number 2
Name: sivakarthik
Date: September 30, 2005 at 01:58:06 Pacific
Reply:

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



0

Response Number 3
Name: Jim Boothe
Date: September 30, 2005 at 06:12:03 Pacific
Reply:

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


0

Response Number 4
Name: sivakarthik
Date: September 30, 2005 at 10:17:27 Pacific
Reply:

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



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Character substitution UNIX server help



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: passing files as argument

multiple filename as argument www.computing.net/answers/unix/multiple-filename-as-argument/6253.html

Permissions - passing a file as the www.computing.net/answers/unix/permissions-passing-a-file-as-the/7910.html

Deleting a file(Name) with spaces www.computing.net/answers/unix/deleting-a-filename-with-spaces/8199.html