Problem using sed in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem using sed in script
# 1  
Old 05-20-2009
Problem using sed in script

Hey guys,

I'm looking to write a script that takes a variable line number and prints that line via sed, but I'm having an issue with the syntax. As I understand it, the sed syntax to print line number 52 (for example) is as follows:

sed -n '52p'
sed '52!d'
sed '52q;d'

But how can you make 52 a variable when everything is surrounded by single quotes? I've tried double quotes and omitting the single quotes to no avail. Does anybody know?

Thanks!
# 2  
Old 05-20-2009
Code:
a=52
sed "${a}q;d" myFile

# 3  
Old 05-20-2009
You rock! Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed or awk script problem

Hi All I am having a file as shown below File1# modyle 1 { test jsj hhsjh 13e3 jsjjs } memP(dbg_trace) { ajjs jsjs jsjs Test(claer) { jsjs (7 Replies)
Discussion started by: kshitij
7 Replies

2. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

3. Shell Programming and Scripting

Problem removing $ using sed in script

I am trying to use the sed command to remove any character that is passed as a parameter to the script. I may want to replace any character in the file (-, =, $, space). I'm running into an issue when passing the $. This is a typical row in the file. "000000B553","--INTERNAL USE... (6 Replies)
Discussion started by: nadneb
6 Replies

4. Shell Programming and Scripting

Problem using sed

Hi Guys, I have been using sed command to find anything between double quotes. But I also have to incorporate something that first checks for single or double quotes and accordingly sed command should be used. Example: set x = '""A""' echo $x | sed 's/.*""\(.*\)"".*/\1/' Answer: A... (4 Replies)
Discussion started by: dixits
4 Replies

5. Shell Programming and Scripting

Shell Script problem with sed

Hello i have a shell script which will go in some folders using for loop, build some programs with gcc and zip the output. then i have to paste the file of that zip file into a yml file which will be further used by a ruby watir script. PROJECT_PATH=/uploads/$PROJECT_FOLDER zip -rq ... (0 Replies)
Discussion started by: vikki1986
0 Replies

6. Shell Programming and Scripting

Sed Script Problem

My file is having the contents like this AND1 (A) { non : hafe on: tc ma : nite } AND1 (B) { non : hafe1 on: tc1 ma : nite1 } AND1 (C) { non : hafe3 on: tc2 ma : nite3 } I have written a sed script to search the patterns AND1(A) and AND1 (B) and delete the entire... (2 Replies)
Discussion started by: shalini_008
2 Replies

7. Shell Programming and Scripting

sed problem

hi all i want to use sed command to replace check_Switch2!192.168.1.1!10.0.0.1 to check_by_nrpe!10.0.0.1!check_AP!192.168.1.1 thanks in advance (1 Reply)
Discussion started by: bondoq
1 Replies

8. Shell Programming and Scripting

Sed problem

Hi guys, I have a problem where by I need to remane a file by moving it to another location. For instance I have a file called change.txt changeA.txt changeB.txt and I need to change the name to change_a1.txt changeA_a2.txt changeB_a3.txt I need a sed regular expression that changes... (3 Replies)
Discussion started by: abch624
3 Replies

9. Shell Programming and Scripting

problem with sed command in shell script.

Guys, I've a problem in the "sed" command used in my shellscripts This is the problamatic line in my shell script: sed -e 's/${line1}/${line1_m}/g' prod_hier_1234.txt > test.txt It doesn't do the job of replacing the string stored in variable 'line1' to 'line1_m'. However If I replace the... (10 Replies)
Discussion started by: bhagat.singh-j
10 Replies

10. UNIX for Dummies Questions & Answers

sed modify problem in script

I am having problems with the following "sed" command only when it is issued within a bash script. #!/bin/bash cat config.xml | sed -e 's/yes/no/g' > newconfig.xml When I enter this command from the command line it works like a charm, but when run in a script as shown it "zero's out" my... (2 Replies)
Discussion started by: darthur
2 Replies
Login or Register to Ask a Question