Mailinglist Archive: opensuse (3637 mails)

< Previous Next >
[OT SED AWK BASH] How to run a shell command for every line in a file?
  • From: wilson@xxxxxxxxxxx (Jonathan Wilson)
  • Date: Wed, 02 May 2001 13:04:44 -0500
  • Message-id: <5.1.0.14.0.20010502125910.02eddec8@xxxxxxxxxxxxxxxx>
Howdy,

In order to run a command form bash fr every file in a directory, let's use tar xzvf for instance, I'd use something like this:

for tarball in ./*.tar.gz; do tar xzvf $tarball ; done

And it would open every tar.gz archive in the current directory.

Now my question is, is it possible to do something like that "for" every line in a file?

In my case, I now have a list of hostnames and I want to run nslookup on each of them with a shell script (so I won't have to do it by hand).

for host in hostnames.lst ; do nslookup $host; done

But obviously I'm going to have to do something more then that in order to feed the hostnames to the shell one at a time.

Possible?

----------------------------------------------------
Jonathan Wilson
System Administrator

Cedar Creek Software http://www.cedarcreeksoftware.com
Central Texas IT http://www.centraltexasit.com


< Previous Next >