I got stuck for the following problem. My shell script is as follows: for i in `sort -u file1.txt` #the small dot here is backquote do echo $i done the file1.txt consists of two sentences : I am a boy you are a girl after I run the script, the output is $ ./li.sh I am a boy you are a girl However, I need the output like I am a boy you are a girl That is , I need variable i to be assigned the value of the whole line not a single word delimited by the space. How should I change my scri
o*a
3 楼
sth like this: for i in `sort -u file1.txt` #the small dot here is backquote do j=`echo $j $i` done echo $j
【在 a*a 的大作中提到】 : I got stuck for the following problem. My shell script is as follows: : for i in `sort -u file1.txt` #the small dot here is backquote : do : echo $i : done : the file1.txt consists of two sentences : : I am a boy : you are a girl : after I run the script, the output is : $ ./li.sh
a*a
4 楼
Dear ouba, firstly thank you so much! I tried your script and the output was ]$./lii.sh I am a boy you are a girl so I can only bother you again and need your further help. What I want is the variable to be assigned with the value of *each line*, say $j=I am a boy firstly then $j =you are a girl. However, because the " echo $j" statement was outside the loop, $j finally get the value of both lines together. Do you have any idea? I'm pretty greenie in Unix and thanks again for your help! ly a
【在 o**a 的大作中提到】 : : sth like this: : for i in `sort -u file1.txt` #the small dot here is backquote : do : j=`echo $j $i` : done : echo $j
o*a
5 楼
sorry, i thought "\n" could be passed to $i. let me think think.
the was
【在 a*a 的大作中提到】 : : Dear ouba, firstly thank you so much! I tried your script and the output was : ]$./lii.sh : I am a boy you are a girl : so I can only bother you again and need your further help. What I want is the : variable to be assigned with the value of *each line*, say $j=I am a boy : firstly then $j =you are a girl. However, because the " echo $j" statement was : outside the loop, $j finally get the value of both lines together. Do you : have any idea? I'm pretty greenie in Unix and thanks again for your help! : ly
o*a
6 楼
but if the original file has # in it, it's replaced by blank afterwards. dunno if there is any line-read like <> in perl. a
o*a
7 楼
i know, it's practical but not perfect. since anything may occur inside the input.
w*n
8 楼
add following before sort IFS=\n works for me br />
【在 a*a 的大作中提到】 : I got stuck for the following problem. My shell script is as follows: : for i in `sort -u file1.txt` #the small dot here is backquote : do : echo $i : done : the file1.txt consists of two sentences : : I am a boy : you are a girl : after I run the script, the output is : $ ./li.sh
l*l
9 楼
#!/bin/sh NUM=`cat file1.txt| wc -l` COUNT=1 while [ $COUNT -le $NUM ] do sort -u file1.txt | sed -n $COUNT\p COUNT=`expr $COUNT + 1` done
【在 a*a 的大作中提到】 : I got stuck for the following problem. My shell script is as follows: : for i in `sort -u file1.txt` #the small dot here is backquote : do : echo $i : done : the file1.txt consists of two sentences : : I am a boy : you are a girl : after I run the script, the output is : $ ./li.sh
o*a
10 楼
this is the kind of cool solution i think:) a
【在 w**n 的大作中提到】 : add following before sort : IFS=\n : works for me : br />
w*n
11 楼
yeah, you're right. it is my typo, actually no export needed