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}/' 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. |
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}/" |
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}/" 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)/" |
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)/" Code:
$cat test.txt |sed -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/$(date '%d\/%m\/%y')/" |
Or, even simpler:
Code:
sed -e "/date/s/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]/`date`/" |
All times are GMT -5. The time now is 07:12 AM. |