want to specific line which i will give through variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting want to specific line which i will give through variable
# 1  
Old 09-22-2006
want to specific line which i will give through variable

Hi,

I have a file on unix which contains

--------------------------------------

1 # Do not remove the following line, or various programs
2 # that require network functionality will fail.
3 127.0.0.1 romhelp3 localhost.localdomain localhost
4
5 10.231.34.66 blind17 # TCH Test Server
6 10.231.34.97 roMltydl ffsrvr # NCR S1600 - dilbert
7 10.8.188.36 lab1 #
---------------------------------------------------
just i wanted to display line that i will give line number through variable

script is like this
------------------
FILE=/home/anupl/ss
echo "enter option"
read ss
sed -n '${ss}p' $FILE
-------------------

I tried with grep and fgrep command but these commands are not working.
so finally i got the sed command that display specific line number.
if i give "sed -n '5p' <file name>" which is working without any problem.
when i passing though a variable it is giving error.....

Pls suggest me to get it dong....
# 2  
Old 09-22-2006
use double quotes
Code:
sed -n "${ss}p" $FILE

# 3  
Old 09-23-2006
Thanks jim

it is working ..... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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. file.dat one two three four ... (1 Reply)
Discussion started by: zzavilz
1 Replies

2. UNIX for Dummies Questions & Answers

Give name for every nth line

Hi all, Greetings. I am facing some troubles and hope that the professionals here could help me. I am handling a large dataset, and part of it is like below: 1 ab139 0 752566 G A 1 ab151 0 846808 T C 1 ab142 0 854250 G A 1 ab061 0 861808 A G 1 ab043 0 873558 T G... (4 Replies)
Discussion started by: Amanda Low
4 Replies

3. Shell Programming and Scripting

Using AWK to get a specific line using a variable

Hi I have a text like this example.input 1 red 2 blue 3 green If I set this c=2 Then try awk 'NR==$c { print $2 }' example.input I do get nothing If I try awk 'NR==2 { print $2 }' example.input i get blue (8 Replies)
Discussion started by: Jotne
8 Replies

4. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

5. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

6. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

7. UNIX for Dummies Questions & Answers

how to give PASSPHRASE to gpg in command line?

Hello sir, I am using "gpg" command to encrypt a file. We generally do it :- then it asks us for :- I want to know how to give this Passphrase in the command line itself !!!I did read the man page but couldnt make out what is the option for it.Can u please help me out !!! (2 Replies)
Discussion started by: nsharath
2 Replies

8. Shell Programming and Scripting

How to read the value from a specific line and column in to a csh variable

Hi All, Although its a basic question the last 2 hours of googling and trying didnt help me to achieve what i want. Maybe some one can help me I have a text file text1.txt: blablablabla A B C D E F and i would like to read to read what is on position E (line 3 column 2) in a... (2 Replies)
Discussion started by: Radamez
2 Replies

9. Solaris

give user permission on specific directory in solaris

dear all does any one give any user write permission using access control list or another way to solve this problem (1 Reply)
Discussion started by: murad.jaber
1 Replies

10. Shell Programming and Scripting

how to give a variable to a command in shell script...

hi all... I am executing a comman in a shell script but the command needs a user input of character 'y' as input so it stops in between...may i know is there is any way of giving that character as input in the shell script itself???...thanks in advance.... (6 Replies)
Discussion started by: santy
6 Replies
Login or Register to Ask a Question