![]() |
|
|
|
|
|||||||
| UNIX Desktop for Dummies Questions & Answers Questions regarding GNOME, KDE, CDE, Open Office, etc go here. All UNIX and Linux Newbies Welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Create a script using DATE command? | thecoffeeguy | Shell Programming and Scripting | 1 | 05-15-2008 03:33 PM |
| trying to create a script to read a flie and loop a command... | Italy87 | UNIX for Advanced & Expert Users | 1 | 03-25-2008 05:44 AM |
| script to count a word in a flie | sipmohan | UNIX for Dummies Questions & Answers | 3 | 02-21-2008 11:39 PM |
| ls while read loop - internal read picking up wrong input | dkieran | Shell Programming and Scripting | 2 | 05-14-2007 12:02 PM |
| AWK create loop for fields | tonet | Shell Programming and Scripting | 1 | 07-07-2005 06:50 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
trying to create a script to read a flie and loop a command...
I tried to explain this earlier, but did a poor job of it. So I am trying again but taking a different approach.....
I have a file called test_words. In this file I have one line with 5 three letter words, with a single space seperating the words.(I.e., "cat car mop red pin") I want to create a script that will read the file and loop each word individually into a command until all words in the file have been used. Use the echo command for arguements sake. the output would look like this: cat car mop red pin The file test_word may change, by adding words or subtracting words, but always use a space as the delimiter. can anyone help with this? Thank you in advance for any and all help on this. |
| Forum Sponsor | ||
|
|
|
|||
|
Try:
tr ' ' '\n' <file |sed "s/^/$CMND /" | sh The above pipe-lined command will put $CMND (i.e. whatever is in CMND variable) before each word as one per line and then will execute all of them, again in sequence. I hope this is what you wanted to do. |
|
|||
|
Shamrock, Thank you that worked perfect!!!! Sham-rocks!!
Thank you all, for your help. for some reason I could not get it to work with what unilover suggested. not sure why but here is the command that worked with Shamrock. for word in $(<file) do response=command {$word is located within command} echo echo "$response" echo "$response" >> ./return-data file=return-data done cat "$file" | lpr echo "All data has been sent to the following file." echo "file" echo "Script complete." Thanks a million all. And I am sorry for posting in two forums. I did not get a sponse, so I thought it was ok, to post in an advance forum. Again, sorry, I am a newb to this forum. |
|||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|