Unix/Linux 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 Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-11-2007
marlonus999's Unix or Linux Image
marlonus999 marlonus999 is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 28 November 2014, 2:36 AM EST
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 Unix and Linux 01-11-2007
anbu23's Unix or Linux Image
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 16 March 2015, 4:56 AM EDT
Location: Bangalore,India
Posts: 2,136
Thanks: 14
Thanked 151 Times in 144 Posts

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

Use double quotes
Sponsored Links
    #3  
Old Unix and Linux 01-11-2007
marlonus999's Unix or Linux Image
marlonus999 marlonus999 is offline
Registered User
 
Join Date: Dec 2006
Last Activity: 28 November 2014, 2:36 AM EST
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... Linux
    #4  
Old Unix and Linux 01-11-2007
anbu23's Unix or Linux Image
anbu23 anbu23 is offline Forum Advisor  
Advisor
 
Join Date: Mar 2006
Last Activity: 16 March 2015, 4:56 AM EDT
Location: Bangalore,India
Posts: 2,136
Thanks: 14
Thanked 151 Times in 144 Posts

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

Sponsored Links
Closed Linux or Unix Question

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



All times are GMT -4. The time now is 01:45 AM.