Problem with variables in sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with variables in sed
# 1  
Old 12-12-2013
Problem with variables in sed

Hello!

I have a problem to insert variables with sed... And I can't find the solution. Smilie
I would like to display one/few line(s) between 2 values.

This line works well
Code:
sed -n '/Dec 12 10:42/,/Dec 12 10:47/p'

Thoses lines with variables doesn't work and I don't find the solution...
Code:
MMCHAR=Dec
DD=12
HBEGINBCK=10:42
HENDBACKUP=10:47
sed -n '/$MMCHAR $DD $HBEGINBCK/,/$MMCHAR $DD $HENDBACKUP/p'
sed -n '/'$MMCHAR $DD $HBEGINBCK'/,/'$MMCHAR $DD $HENDBACKUP'/p'
sed -n '/"$MMCHAR $DD $HBEGINBCK"/,/"$MMCHAR $DD $HENDBACKUP"/p'

If someone have the solution... Thanks!!Smilie
# 2  
Old 12-12-2013
Can you try this:
Code:
sed -n "/$MMCHAR $DD $HBEGINBCK/,/$MMCHAR $DD $HENDBACKUP/p"

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 12-12-2013
Thank you balajesuri!!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem getting sed to work with variables

Hello, I am processing text files looking for a string and replacing the first occurrence of the string with something else. For the text,id Name 1 methyl-(2-methylpropoxy)-oxoammonium 2 N-amino-N-(methylamino)-2-nitrosoethanamine 3 3-methoxy-3-methyloxazolidin-3-ium... (12 Replies)
Discussion started by: LMHmedchem
12 Replies

2. Shell Programming and Scripting

sed with variables

Im trying to use sed to print value that matches the value in variable and all lines after that. grep "Something" test.txt | sed -e '/{$variable}/,$b' -e 'd' I cant get it work, if I replace the $variable with the value it contains, it works fine... (10 Replies)
Discussion started by: olkkis
10 Replies

3. Shell Programming and Scripting

Using Variables with SED

All I am trying to produce the following in /etc/ssh/sshd_config, # IPv4 only #ListenAddress 0.0.0.0 # IPv4 & IPv6 ListenAddress :: to # IPv4 only ListenAddress <user-entry> ListenAddress <user-entry> # IPv4 & IPv6 #ListenAddress :: The number of user entries can vary. ... (1 Reply)
Discussion started by: miyoung999
1 Replies

4. Shell Programming and Scripting

Sed with variables problem

I am writing a script with a sed call that needs to use a variable and still have quotations be present in the substitution. Example: sed -i "s/Replacable.\+$/Replaced="root@$VAR"/g" this outputs: where $VAR = place Replaced=root@place and i need Replaced="root@place" ... (2 Replies)
Discussion started by: mcdef
2 Replies

5. Shell Programming and Scripting

SED 4.1.4 - INI File Change Problem in Variables= in Specific [Sections] (Guru Help)

GNU sed version 4.1.4 on Windows XP SP3 from GnuWin32 I think that I've come across a seemingly simple text file change problem on a INI formatted file that I can't do with SED without side effects edge cases biting me. I've tried to think of various ways of doing this elegantly and quickly... (5 Replies)
Discussion started by: JakFrost
5 Replies

6. Shell Programming and Scripting

using variables with sed

I'm trying to get sed to cut and replace using variables, but it doesnt seem to work, when I run this the mod time of the file does get updated. Is my syntax incorrect in the sed command? Thanks #!/usr/bin/ksh #Modify header set -x HEAD=$(cat PBN2CPR1.TXT | awk 'BEGIN { FS = ","... (1 Reply)
Discussion started by: ddurden7
1 Replies

7. Shell Programming and Scripting

Sed variables

HELP!!! I'm keep getting "sed: Function s/PETS/dog cannot be parsed." I have 2 files that list... # cat FILE1.txt dog cat mouse # cat FILE2.txt my pets are PETS I put this into a variable... # A=`cat FILE1.txt` # sed "s/PETS/$A" FILE2.txt > FILE3.txt (5 Replies)
Discussion started by: Zenwork
5 Replies

8. Shell Programming and Scripting

Using sed with variables (again!)

Hi, I'm trying to use sed to delete the last three lines of a file. I currently have: # get the amount of lines in the file foldernum=`wc -l File_In.txt | cut -c1-8` # remove the lines in the file sed "${foldernum}-3,${foldernum}d" File_In.txt > File_Out.txt I get the error - sed:... (5 Replies)
Discussion started by: Mr_Plow
5 Replies

9. UNIX for Advanced & Expert Users

using variables in sed

a=2 sed -n "/${a}/p" list | cut -d "#" -f1 this dosen't print only second line..... how can it b done.... (1 Reply)
Discussion started by: bishweshwar
1 Replies

10. UNIX for Dummies Questions & Answers

Using sed with variables

All - I have a situation where I have some hardcoded directories in a file. I want to be able to search for string that I know will always be the same in each environment and then replace that entire line with the new environment specific information. I am using the sed command to do this, but... (2 Replies)
Discussion started by: Mark_A_Tritz
2 Replies
Login or Register to Ask a Question