How can you use the contents of a file as command line parameters for a script? The file has 3 colums and each colume I want to be command line $1 $2 $3 respectivly for the script. $script < file does not seem to work Thanks and Regards Mark
* Mark Hounschell (markh@compro.net) [020509 09:06]:
How can you use the contents of a file as command line parameters for a script? The file has 3 colums and each colume I want to be command line $1 $2 $3 respectivly for the script.
$script < file does not seem to work
while read rec do your_command_here $rec done < file_with_args You can also do this in awk but it's a little more, uhm..., awkward. -- -ckm
Christopher Mahmood wrote:
* Mark Hounschell (markh@compro.net) [020509 09:06]:
How can you use the contents of a file as command line parameters for a script? The file has 3 colums and each colume I want to be command line $1 $2 $3 respectivly for the script.
$script < file does not seem to work
while read rec do your_command_here $rec done < file_with_args
You can also do this in awk but it's a little more, uhm..., awkward.
--
Yep that's what I came up with also just before your post. Thanks. It works perfectly.. Mark
I would probably say less awkward in awk, since awk reads each line in a file automatically where in a shell script you must read each line individually in a loop. Much depends what you are going to do with the contents of the file and the command line arguments. AWK does not naturally handle command line arguments where shell does. But AWK handles individual records more elegantly, and provides you with the number of fields in each record and the record number of the line you are reading. A shell script that uses both sed and awk can do some very powerful things (as can perl, tcl and python). On 9 May 2002 at 11:18, Christopher Mahmood wrote:
* Mark Hounschell (markh@compro.net) [020509 09:06]:
How can you use the contents of a file as command line parameters for a script? The file has 3 colums and each colume I want to be command line $1 $2 $3 respectivly for the script.
$script < file does not seem to work
while read rec do your_command_here $rec done < file_with_args
You can also do this in awk but it's a little more, uhm..., awkward.
--
-ckm
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com
-- Jerry Feldman Portfolio Partner Engineering 508-467-4315 http://www.testdrive.compaq.com/linux/ Hewlett-Packard Company 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752
* Jerry Feldman (gerald.feldman@hp.com) [020509 13:22]:
I would probably say less awkward in awk, since awk reads each line in a file automatically where in a shell script you must read each line individually in a loop.
awk won't help much here I think since there's not easy way to pass variables to a system(). If I had to I'd do something like: awk '{ print $0 }'< file_with_args | xargs -n1 ls Ugly. What did you have in mind? -- -ckm
The issue is exactly what did the original poser want to do? It all comes down to the right tool for the right job. One of the homework assignments I give to my students to write as a Korn Shell script is rather challenging, but can be performed with ease using AWK. awk 'BEGIN { print headings } { print $1, $2, $4, $3, $3 * $4 }' < file Or, you can set up awk in a script: #!awk -f BEGIN { -- begin stuff -- } condition { action } condition { action } END { end stuff like totals } Like perl, awk has associative arrays. It all comes down to what do you need to do, and what tool is the most appropriate for the job. Perl's intent was to subsume both awk and sed. Passing parameters to system() is simple: command=sprintf("%s %s $s", "Linux command", option1, option2) system(command) You can easily concatenate stuff to the command variable You can also pipe things to commands. Most people think about AWK as an inline command: awk 'script' file On 9 May 2002 at 14:17, Christopher Mahmood wrote:
* Jerry Feldman (gerald.feldman@hp.com) [020509 13:22]:
I would probably say less awkward in awk, since awk reads each line in a file automatically where in a shell script you must read each line individually in a loop.
awk won't help much here I think since there's not easy way to pass variables to a system(). If I had to I'd do something like:
awk '{ print $0 }'< file_with_args | xargs -n1 ls
Ugly.
What did you have in mind?
--
-ckm
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com
-- Jerry Feldman Portfolio Partner Engineering 508-467-4315 http://www.testdrive.compaq.com/linux/ Hewlett-Packard Company 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752
* Jerry Feldman (gerald.feldman@hp.com) [020509 15:15]:
Passing parameters to system() is simple: command=sprintf("%s %s $s", "Linux command", option1, option2) system(command) You can easily concatenate stuff to the command variable You can also pipe things to commands. Most people think about AWK as an inline command: awk 'script' file
I know, I know...for what he wanted (I think anyway) the awk solution is really ugly. Anyway, I originally said "awkward" b/c I liked the pun :) Contact me off the list and we can come up with the INTERCAL example. -- -ckm
participants (4)
-
Alexandr Malusek
-
Christopher Mahmood
-
Jerry Feldman
-
Mark Hounschell