![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| query on how to search for a line and read 4th word from that line | jaggesh | UNIX for Dummies Questions & Answers | 4 | 07-01-2008 10:21 PM |
| Alternative for a while read line loop | kabs | UNIX for Dummies Questions & Answers | 2 | 04-01-2008 12:25 PM |
| ls while read loop - internal read picking up wrong input | dkieran | Shell Programming and Scripting | 2 | 05-14-2007 03:02 PM |
| While read loop and rsh | 104234 | UNIX for Advanced & Expert Users | 1 | 01-15-2006 11:53 AM |
| Nested while read line loop | Rakker | Shell Programming and Scripting | 7 | 06-24-2005 07:42 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
read line in a for loop
Hi All,
How can we use read line using the index value of a FOR loop? eg: pt_mstr,pt_status,8 pt_mstr,pt_buyer,8 pt_mstr,pt_sfty_stk,8 pt_mstr,pt_ord_pol,3 pt_mstr,pt_capacity,8 pt_mstr,pt_plan_ord,3 pt_mstr,pt_ord_mult,8 From this file i want to read the line2, 3 and 4 only using a FOR Loop. for (( i=2; $i <= 4; i++ )) do read line echo $line done This will read 3 lines from the top, but what i want is the lines from the index of the FOR Loop. Here the index of the for loop is 2, 3 and 4 so i want the line2 , 3 and 4 Thanks, Balaji |
|
||||
|
another method
file.txt
-------------------------------- pt_mstr,pt_status,8 pt_mstr,pt_buyer,8 pt_mstr,pt_sfty_stk,8 pt_mstr,pt_ord_pol,3 pt_mstr,pt_capacity,8 pt_mstr,pt_plan_ord,3 pt_mstr,pt_ord_mult,8 --------------------------------- Code:
#! /bin/bash set $(cat file.txt) for (( i=2; $i <= 4; i++ )) do eval echo \$$i done Code:
#! /bin/bash for i in `cat` do ((j++)) if [ $j -eq 2 -o $j -eq 3 -o $j -eq 4 ] then echo $i fi done Code:
cat >> temp && sed -n '2,4p' temp Last edited by lifegeek; 10-29-2008 at 10:24 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|