I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file.
I'm struggling to see how each line can be treated differently, and captured as a variable.
If I try using the for n in `cat filename` approach, it simply takes each word from the filename.
And since the file may have multiple lines, I want to use a text file as the basis for a shell script, using variables taken from the file on a line by line basis.
Is there a simple way? Searching google and other search engines pulls up too many read herrings or inappropriate pages.
So if I understand it, you might have a file like this:
--- filename ---
file1 10
file2 20
file3 30
file4 40
---------------
Say I want to get the word count of each file and print next to it the corresponding 10, 20, 30, or 40..
~$ cat filename | while read line; do x=`echo $line | awk '{print $1}'`; y=`echo $line | awk '{print $2}'`; echo `wc -l $x` $y; done