alexcol
December 16, 2006, 1:58pm
1
hello, hope you can help me:
ive got a file called archivos
The content or structure of this file is
./chu0/filechu
./chu1/filechu
I extract each line from this file manually and redirect to a file, and it Works fine, so the command line is:
awk �/chu0/ {print $0}' < archivos > portal0
awk �/chu1/ {print $0}' < archivos > portal1
The problem is to extract these lines automatically, an i dont know how to do this, with a loop for example.
and i tried but gets some error whit this command
i=0
while (i<=num)
do
awk -v i=$i � /chu$i/ {print $0} < archivos > portal$i
done
how can i do that so i can extract lines from this file automatically?can you help me? please.
#!/bin/ksh
while read myLine
do
echo "line-> [${myLine}]"
done < archivos
alexcol
December 16, 2006, 2:40pm
3
Thanks for yor reply, but in this script how the code will be in born shell.?
try it as 'bourne' and see what happens.
alexcol
December 16, 2006, 3:07pm
5
This code lnly print the output on the screen:
line-> [./chu0/filechu]
line-> [./chu1/filechu]
But, i want is to redirect the content of each line to a file
i.e. file0 the content must be ./chu0/filechu
and file1 the content must be ./chu1/filechu
thanks
#!/bin/sh
i=0
while read myLine
do
echo "${myLine}" > "file${i}"
i=`expr $i + 1`
done < archivos
alexcol
December 16, 2006, 3:23pm
7
Could you please comment each line what it does?. i am new at unix, why you quote some lines.
Thanks again.
alexcol
December 16, 2006, 3:48pm
8
Hello
Thas working, but to be sincere dont undesrtand so much
ie what some lines have curly braces and double quotes, why?
reborg
December 16, 2006, 4:25pm
9
try reading the man page for sh.
Spectificall the sections on Parameter Expansion and quoting.