A question on SED | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

A question on SED

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-11-2007
marlonus999's Avatar
marlonus999 marlonus999 is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 16 April 2014, 2:56 AM EDT
Location: KL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Bug A question on SED

Hi Folks,

How do I pass a variable on sed (as a regular expression)???

I need to use a variable as a regexp in a sed command. The variable happens to be a time stamp which I fetch from another command.

To illustrate:

Suppose the value of variable var is....
var=10:20:22

I notice that this command doesn't work:

sed '1,/$var/d' textfile1

(I'm trying to delete the first line upto the first instance of var in the file textfile1.

Please help...tnx!
Sponsored Links
    #2  
Old 01-11-2007
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 21 November 2014, 4:45 AM EST
Location: Bangalore,India
Posts: 2,091
Thanks: 12
Thanked 131 Times in 126 Posts

Code:
sed "1,/$var/d" textfile1

Use double quotes
Sponsored Links
    #3  
Old 01-11-2007
marlonus999's Avatar
marlonus999 marlonus999 is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 16 April 2014, 2:56 AM EDT
Location: KL
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
A Question on SED

Thanks very much...can you be so kind to show me the sed command if I wanted to delete from first line to the LAST INSTANCE of the variable...
    #4  
Old 01-11-2007
anbu23's Avatar
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 21 November 2014, 4:45 AM EST
Location: Bangalore,India
Posts: 2,091
Thanks: 12
Thanked 131 Times in 126 Posts

Code:
sed -n -e ":a" -e "$ p;N;/$var/d;b a" file

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
sed and awk question melanie_pfefer Shell Programming and Scripting 3 01-22-2008 05:49 PM
Question mirusnet Shell Programming and Scripting 2 01-22-2008 09:48 AM
X Question af6 UNIX for Dummies Questions & Answers 5 02-22-2005 09:50 PM
FTP Question lesstjm UNIX for Advanced & Expert Users 6 12-29-2004 05:50 AM



All times are GMT -4. The time now is 04:29 AM.