Powered by Invision Power Board


  Reply to this topicStart new topicStart Poll

> read input within a script, input only certain lines
maximus
Posted: Apr 5 2005, 10:11 PM
Quote Post


Newbie
*

Group: Members
Posts: 3
Member No.: 844
Joined: 3-March 05



Hi All,

In my script, I want to read input from another file. The input file contains many lines, however, I only want read certain specific lines as input.

example: input.txt

test1
test2
test3
bad1
bad2
bad3

In my script, when I use the read command like this:

while read line
do

the entire input file is read, all 6 lines. How can I specify only certain lines as input? Lets say, I only want first 3 lines as input, how can I do that?

Thanks in advance.
PMEmail Poster
Top
venkat_venkamolla
Posted: Apr 6 2005, 07:44 AM
Quote Post


User Level: 2
**

Group: Members
Posts: 13
Member No.: 906
Joined: 4-April 05



you can do that by selecting the lines into a variable

ex:

# here you get the first 3 lines from your file
lp_lines=`cat input.txt|head -3`

# here you read the each line from the selected in a loop
for l_line in ${lp_lines};
do
----done your process here--
done


is it ok....
PMEmail Poster
Top
andyb1ack
Posted: May 12 2005, 02:38 PM
Quote Post


User Level: 4
****

Group: Members
Posts: 98
Member No.: 513
Joined: 9-September 04



Or in the same vein:
CODE
head -3 input.txt |while read line
do
 echo Processing line $line
done


or even
CODE
grep test input.txt |while read line
do
 echo Processing line $line
done
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Shells & Scripting | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.0463 ]   [ 12 queries used ]   [ GZIP Enabled ]




Partners: Cambridge Plus :: <Link Available> :: 3D Mechanical Design :: <Link Available>
Unix Man Pages / Linux Man Pages :: HiFi Forum :: SIP VoIP Phone & Provider Reviews :: UNIX/Linux Forum Archives

More info on advertising on Unix/Linux Forum