LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   execute a command with sed (https://www.linuxquestions.org/questions/programming-9/execute-a-command-with-sed-431741/)

angel115 04-04-2006 05:53 PM

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.

gilead 04-04-2006 06:08 PM

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}/"

angel115 04-05-2006 05:22 AM

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}


angel115 04-05-2006 05:40 AM

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

theNbomr 04-05-2006 03:40 PM

Or, even simpler:

Code:

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


All times are GMT -5. The time now is 07:12 AM.