Reading a multiple file inside loop and store!
Hi ,
This might be a repeated question but i searched alot to figure out a way.. but unfortunately i couldn't find... i have a file file.list cat file.list text1:text2:text3 text4:text5:text6 .... am writing a script to manipulate the strings and store it in a vairable outside the loop Code:
IFS=':' but, i want the files to be read line by line and use the inputs outside the loop... Am sorry if this is already existing query or someone might have answered.. but i couldn't figure out .... Any help would be really appreciated !! Thanks... |
Firstly, the echoes are redundant as you can simply assign one variable to another:
Code:
a=$fa Currently the value of variable 'c' will of course only hold the last value assigned to it, which in your example would be 'text6'. Would you explain further what you think "should" be in 'c'? |
yeah...correct ... it will display text6...
Precisely, If the script reads the first line it will have 3 variable that is in this case a,b,c and i want those variables to be used outside the loop .... and subsequently after reading each line it has to perform some tasks with the variable outside the loop.... please guide to use the variables stored and make use of that outside the loop anywhere in the script.. Hope this serves the question ! am not constraint with while we can use any... |
If I understand correctly I would use arrays to access your data:
Code:
while IFS=':' read fa sa ta |
Its giving error... :(
./small.sh: line 39: syntax error near unexpected token `"$fa"' ./small.sh: line 39: ` a+=( "$fa" )' am using bash shell and aix 5.3 |
Quote:
--C |
lemme explain my whole requirement.. hope that fills the gap
i have to execute a sql in unix based upon the input values of the file.list once if i read the first line.. it has to sent the inputs to other file @$a:$b/$c in this format ...i have to redirect the output to other file say output.txt like wise it has to manipulate for all the lines of the file.list If you need more explanation... i will give .. but... am not getting any method to perform this... |
Quote:
|
I would guess it may be an older version of bash (needs to be 3.1 or newer).
Why do you need to store in anything after the loop if all you need to do is simply make a new file? Code:
while IFS=':' read fa sa ta |
thanks grail..that was a good one....:)
but...small prob in that.... i have to echo it and ask for the user input if the details provided are correct...later on only i can redirect it... and also sorry for confusion...is there any other way that i can use it some where outside the loop instead of redirecting it ?... that would be really helpful i think.. because....instead of creating a file i can use outside the loop right ?...and perform the same which i want to do in the created file... let me give my entire script Code:
IFS=":" Sorry for bothering !! |
The point is that if you use
Code:
while read If you have multiple lines on input to process, then out the 'done<file' at the bottom of the script. |
Does this help?
Code:
|
@chrism01 - The example you provided is the one that does not create a sub shell, however the following would:
Code:
cat file | while ... outside the loop. |
Thanks Bsat.. ..
Thanks grail.... it works exactly... i can call the variable based upon the i value......thanks lot:) |
All times are GMT -5. The time now is 07:52 PM. |