how to read certain line of file, and output to variable?
hi,
I have a file : arg.txt oi1 oi2 oi3 oi4 k2 k3 l4 l5 l6 the line nubmers are fixed.but elements in each line are seperated by space and their numbers are random, not always same. that's mean, next time you read arg.txt maybe will looks like this: oi1 oi2 oi3 oi4 oi5 k2 k3 l4 l5 l6 how to read certain line of file, and put each element in certain line to variables. for exmple,I want to output line 1 to variables: line1=getline 1 arg.txt # this is only a assume,not real code. y=(number of line1) # I don't know how to get it. for (( i =0; i<=y; i++ )) do argi=$i done #arg1 arg2 arg3 ...arg(y-1) are source files, argy are desionation directory. cp arg1 arg2 arg3 ...arg(y-1) argy I'm new to bash script,sorry for the mess. thanks! |
First off, I don’t see what this has to do with Red Hat…
As for your problem, the most elegant solution involves bash arrays like so: Code:
while read fullline; do I suggest you read up on bash arrays. If you have any questions, just post. |
thanks! it works!
|
All times are GMT -5. The time now is 03:21 PM. |