LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2006, 05:53 PM   #1
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Rep: Reputation: 79
execute a command with sed


Hi every one

I'm looking to execure a command with sed with out using any external variable (as possible)

here is what i want to do:
i want to replaice the date in a text file like:

the date today is: 04/05/06

so i try this: (which is meen "looking for the first line in this text file who is containing the patern date and replace the date in this line by the out put of the command".)
Code:
sed -e '/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/{my commande}/'
But it doesn't work i try to put my comand beween (my commande) but it's the same problem.
I've looking for the solution in a lot of forums and DOCs on internet but i can't find any example where some one use a command to replace the patern.

If any one got an idea, i would be very pleased.

Kind regards,
angel.
 
Old 04-04-2006, 06:08 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
I don't have a PC here to test it on, but have you tried double quotes instead of single quotes? For example:
Code:
sed -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/{my commande}/"
 
Old 04-05-2006, 05:22 AM   #3
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Original Poster
Rep: Reputation: 79
Hi

It's the same thing
Code:
$cat test.txt |sed -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/{my commande}/"
$The date of today is: {my commande}
it doesn't execute the command but just print it insted of the maching patern.

so i try this as well
Code:
$cat test.txt |sed -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/(my commande)/"
$The date of today is: (my commande)

$cat test.txt |sed -e '/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/(my commande)/'
$The date of today is: {my commande}
 
Old 04-05-2006, 05:40 AM   #4
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Original Poster
Rep: Reputation: 79
Hey i found it :-)

Code:
$cat test.txt |sed -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/$(my command)/"
$The date of today is: here is the out put of my command
So now if i do some thing like
Code:
$cat test.txt |sed -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/$(date '%d\/%m\/%y')/"
$The date of today is: 04/05/06
:-P

Last edited by angel115; 04-05-2006 at 05:41 AM.
 
Old 04-05-2006, 03:40 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Or, even simpler:

Code:
sed  -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/`date`/"
--- rod.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM
sed command pazvant Linux - Software 2 05-09-2004 12:58 PM
sed command linuxdev Linux - Newbie 9 02-24-2004 04:50 PM
sed Command linuxdev Linux - Newbie 3 02-09-2004 11:27 AM
sed command kwigibo Linux - General 3 04-21-2002 04:11 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration