hi,
my first question is :-
i would like to know how do i loop through the output of a variable.
for ex:- if i have a variable called x and echo $x gives the output like
feb 19 07
feb 20 07
feb 21 07
i would like to know how do i loop through this since it is separated and i woul be using this output elsewhere also.
My second question is :-
how do i merge two outputs which can be looped.
example :-
i have the output in one file as
xyz|123|27|feb|2003
wer|342|23|feb|2005
sde|143|30|feb|2006
the output of the second file is
99991231 feb 15
20061121 feb 23
20060915 feb 25
now i would like the final output to be
xyz|123|27|feb|2003|99991231 feb 15
wer|342|23|feb|2005|20061121 feb 23
sde|143|30|feb|2006|20060915 feb 25
thanks a lot in advance.
You would not get that output from 'echo $x'; you might get it from 'echo "$x"' (note the quotes).
What exactly is the content of "$x". Use this to see it:
printf "%s\n" "$x"
If you want to loop through each word in the variable:
for var in $x
do
printf "var=%s\n" "$var"
done
If there are multiple lines in the variable, and you want each line separately, change IFS to a newline and then use a for loop:
IFS='
'
for var in $x
do
printf "var=%s\n" "$var"
done
IF you want to merge line 1 from file1 with line 1 from file2, and line 2 with line 2, etc., use paste:
paste -d\| file1 file2