Operating System - HP-UX
1820214 Members
3874 Online
109620 Solutions
New Discussion юеВ

direct execution of many similar commands

 
SOLVED
Go to solution
Klaus  Frank
Frequent Advisor

direct execution of many similar commands

Hallo to all

frequently I get to run a command on a number of files or parameters that come from a file. Usually I do something like:

ls -1 | awk ?{print "my_script " $0 }' > execfile
or
cat datafile | awk ..... > execfile

This works fine but not all at once. i.e. I have to run the execfile aftrwards.

and because time is money I am looking for an on line execution of this sequence of commands that is generated by the above lines without the need of an additional execfile.

How can I tell the shell (ksh) to run all commands directly as they come out of the awk.
Must be something with "command substitution" such as ` ` or $(... ) ?

any ideas ?
thanks
Klaus
... we all can make it with a little help ...
8 REPLIES 8
Volker Borowski
Honored Contributor
Solution

Re: direct execution of many similar commands

?hm, how about the most simple solution ?

> exefile ????

| sh !!!!


echo ls -l \\n ls -l \\n | sh

will execute "ls -l" twice !

Volker

Joseph C. Denman
Honored Contributor

Re: direct execution of many similar commands

You could try this????


ls -1 | awk ?{print "my_script " $0 }' > execfile
cat execfile | while read line
do
${line}
done


...jcd...


If I had only read the instructions first??
Patrick Wallek
Honored Contributor

Re: direct execution of many similar commands

How about something like:

cd /dir
for i in `ls -1`
do
/other_dir/my_script $i
done

or

cd /dir
ls -1 > datafile
for i in `cat datafile`
do
/other_dir/myscript $i
done
James R. Ferguson
Acclaimed Contributor

Re: direct execution of many similar commands

Klaus:

By way of example, how about something like this:

# ls -l|awk 'NR != 1 {system ("grep token " $9)}'

...JRF...
Alan Riggs
Honored Contributor

Re: direct execution of many similar commands

Have you tried replacein "> execfile" with "|xargs sh"
Wieslaw Krajewski
Honored Contributor

Re: direct execution of many similar commands

Hi,

And one more possibilty:

ls -1 | while read name
do
my_script $name
done
Permanent training makes master
Vincenzo Restuccia
Honored Contributor

Re: direct execution of many similar commands

ls -l|awk '{print $9}'|sh
federico_3
Honored Contributor

Re: direct execution of many similar commands

I'd do like this:

ls -1 | awk '{ system("my_prog" $0)}'

or
ls -1 | awk '{print "my_prog " $0}'| sh

federico