Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use column data in text file as arguments to command

Status
Not open for further replies.

phurtt

Technical User
Dec 10, 2001
1
US
I have a file, we'll call it text.out. It looks like this:

aaa bb1
ccc bb2
ddd bb3
eee bb4
...etc, etc

I have to be able to pass the information from the first line "aaa" and "bbb" to a single command. For instance, the final command should look something like:

copy "aaa" to "bb1" and call it "bb2, or bb3, or bb4"

This is a very simplistic explanation, but if somebody could clue me in, I could translate it into the real situation. I guess my sticking point is being able to take the first two fields out of the test file, and parse them into a command line.

Also, as an extra twist, the third column can contain a possibility of only 4 combinations. The first combination used (bb1) cannot be the same as the second (bb2, bb3, bb4).

Thanks a bunch!
 
Here's an example with an echo and appending
and adding some little tweaks, a hyphen for shell
getopts type stuff, and a calculated extra int
tagged to the end of the string.

awk ' {
cmd = "echo " $1 " -" $2 dest
dest = substr($2,4,4) ; dest += dest
system(command)
}' text.out

Hope this is what you wanted. Should work fine with
cp.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top