Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Print specific line using a variable

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 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 04:05 AM..
Sponsored Links
Old Unix and Linux 07-10-2013
zaxxon's Unix or Linux Image
zaxxon zaxxon is offline Forum Staff  
code tag tagger
Join Date: Sep 2007
Last Activity: 21 September 2017, 3:44 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,569
Thanks: 175
Thanked 560 Times in 481 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 04:45 AM.