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
    #1  
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.

Code:
file.dat
one
two
three
four

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...

Thanks,
zzavilz

Last edited by vbe; 07-10-2013 at 04:05 AM..
Sponsored Links
    #2  
Old 07-10-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 28 August 2014, 10:17 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,227
Thanks: 121
Thanked 451 Times in 411 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 02: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 05:17 AM
Print specific pattern line in c++ cpp_beginner Programming 10 07-07-2011 11:26 AM
Search in specific position and print the whole line ssantoshss Shell Programming and Scripting 4 03-11-2010 05:07 AM
Print a message at specific line on prompt Niroj Shell Programming and Scripting 5 12-11-2008 01:55 AM



All times are GMT -4. The time now is 06:16 AM.