Attempting to read data from a text file and inputting the variable text to a script

0

I have a file with 25 single word entries, I need a script to read through the file one line at a time and input the variable phrase into a second script that will generate a individual file based on the variable phrase name. I'm thinking it might require AWK which I'm inexperienced with. or PERL which I have no experience with. Any help would be greatly appreciated.

user247138

Posted 2013-08-20T23:08:25.240

Reputation:

Please try to explain your problem more clearly.  What does the first script need to do?  What is the relationship between the “single word entries” in the file and the “variable phrases”?  What is the structure of the first file?  25 lines, one word per line?  All 25 words on one line?  A mixture?  And where do environment variables fit in? – Scott – 2013-08-21T00:01:12.510

all it needs to do is read each variable or line which in this case is a list of 25 stock symbols in a text file into a second script. there is only one symbol per line or 25 lines. Also the symbols change every 24 hours. – None – 2013-08-21T02:43:27.273

Answers

1

You can do it with a simple loop:

for entry in $(cat file_with_25_entries); do echo $entry; done

Just replace echo with your script.

Paulo Almeida

Posted 2013-08-20T23:08:25.240

Reputation: 694

0

If I understood you correctly, you want a script to read lines from a file containing 25 lines (with one "phrase" per line) and create 25 files named after each of these phrases. If this is indeed your use case, you can do

while read -r line;do
    touch "$line" || echo "Couldn't create \"$line\"" && exit 1
done < your_file_here

Joseph R.

Posted 2013-08-20T23:08:25.240

Reputation: 474