parse file and use output to run a script
I'm trying to grab text out of a line in a file, and then use those words to run another script. This is all bash scripts.
Here is an example of the line I'm trying to grab text out of and how it's formatted: one|two|three|four|five|six|seven|eight|nine I'm using a combination of grep and awk to grab just that line, and then two of the words out of that line. When I run the command by itself: cat file | grep -v "^\#" | awk -F "|" '{print $2, $4}' it returns what I'm looking for: two four I need to run another script using "two four" as input and I'm using a for loop to do a couple things, example: for i in $(cat file | grep -v "^\#" | awk -F "|" '{print $2, $4}'); do; echo "Adding '$i' to these files"; /bin/sh /pathetoscript/script $i; done It errors out because it's now placing the output of the cat/grep/awk command as two separate lines, so instead of "two four", it's doing: two four Obviously I'm pretty new to bash scripting, so bear with me, I understand I may not being doing this in the best way possible. I hope I added enough info for everyone to understand. I've tried looking around at a lot of guides/tutorials, and I just can't find an answer to this. Thanks |
You should get rid of the for loop and use a while read loop.
Something like this: Code:
$ awk -F"|" '{ print $2, $4 }' input | \ Bash:
Sed and Awk: |
Quote:
/pathtoscript/script two four. Maybe I didn't explain things well enough. |
I just gave an example, not a copy/paste solution.
Maybe this clears things up more: Code:
awk -F"|" '!/^#/ { print $2, $4 }' input | \ |
sorry, i guess i was thrown off by things being on two lines in your example. that did the trick. thanks so much for the help!
Quote:
|
All times are GMT -5. The time now is 03:54 AM. |