Print specific line using a variable | Unix Linux Forums | Shell Programming and Scripting

  Go Back    

Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Print specific line using a variable

Shell Programming and Scripting

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 07-10-2013
zzavilz zzavilz is offline
Registered User
Join Date: Nov 2012
Last Activity: 18 September 2013, 1:22 AM EDT
Posts: 16
Thanks: 5
Thanked 1 Time in 1 Post
Print specific line using a variable

Hi Everyone,

Is there a way I can print specific lines using sed -n '3,3p' file.dat or awk 'FNR==3' file.dat when using variable?

For example, I have this script (get_line.ksh) that accepts line parameter that a user wanted to print in the file.dat.


So if the user ran the script with ./get_line.ksh 4, the script would display four. If the user ran the script with ./get_line.ksh 3, the script would display three and so on...


Last edited by vbe; 07-10-2013 at 05:05 AM..
Sponsored Links
Old 07-10-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
Join Date: Sep 2007
Last Activity: 31 January 2015, 8:41 AM EST
Location: St. Gallen, Switzerland
Posts: 6,256
Thanks: 126
Thanked 455 Times in 414 Posts
a) Sure, try it out with sed or awk - you can't break anything.
b) Where is the starting point (line number? string pattern?)?
c) Is this homework?

Have a look into positional parameters for shells.
awk takes variables with -v and for sed you can surround the code with either " at the end and start or have the shell variable separated with some more of these: ' .
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Print String Every Specific Line attila Shell Programming and Scripting 4 02-05-2013 03:35 AM
How to print line starts with specific word and contains specific word using sed? tmalik79 UNIX for Dummies Questions & Answers 11 10-11-2011 06:17 AM
Print specific pattern line in c++ cpp_beginner Programming 10 07-07-2011 12:26 PM
Search in specific position and print the whole line ssantoshss Shell Programming and Scripting 4 03-11-2010 06:07 AM
Print a message at specific line on prompt Niroj Shell Programming and Scripting 5 12-11-2008 02:55 AM

All times are GMT -4. The time now is 12:05 AM.