![]() |
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 |
| extract a line from a file using the line number | grandtheftander | Shell Programming and Scripting | 7 | 01-22-2009 10:24 AM |
| Using grep to extract line number | mskarica | Shell Programming and Scripting | 8 | 06-26-2008 02:47 AM |
| Adding a columnfrom a specifit line number to a specific line number | Ezy | Shell Programming and Scripting | 2 | 05-12-2008 08:29 AM |
| Appending the line number and a seperator to each line of a file ? | pjcwhite | Shell Programming and Scripting | 4 | 03-21-2007 01:29 AM |
| Get line form file by line number | corny | Shell Programming and Scripting | 3 | 08-25-2006 12:18 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Extract a line from a file using the line number
I have a shell script and want to assign a value to a variable. The value is the line exctrated from a file using the line number. The line number it is not fix, and could change any time.
I have tried sed, awk, head .. See my script # Get randome line number from the file #selectedline = `awk 'NR==$randomline {print $0}' $filename` #awk 'NR==$randomline {print $0}' $filename selectedline=`sed -n "${randomline}{p;q;}" $filename` #sed -n "${randomline}{p;q;}" $filename #selectedline=`head -$randomline $filename |tail -1` #head -${randomline} $filename |tail -1 echo "Random line = $selectedline" The problem is that after getting the desired line specified by randomline, the entire file is expanded in the variable selectedline. This the case only ,when assigned to a variable. Need help |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|