|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
String replace
I want to replace the last date pattern with the current day date my file looks like Code:
>cat sample.dat 1,parameter 2012-06-10 2,parameter 2012-06-10 I want in the below format Code:
1,parameter 2012-06-11 2,parameter 2012-06-11 I tried Code:
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/`date +"%Y-%m-%d"/g`' sample.datthis is not working ...can any body help me
Last edited by zaxxon; 06-11-2012 at 04:13 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
i have tried Code:
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/'`date +"%Y-%m-%d"`'/g' sample.txtalso i tried Code:
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$//g' sample.txtbut both showing me the same results ... Code:
1,parameter 2012-06-10 2,parameter 2012-06-10 i think the regular expression is not correct.. please help Last edited by Scrutinizer; 06-13-2012 at 04:01 AM.. Reason: code tags |
|
#5
|
||||
|
||||
|
The shell will not look at your date command which you've protected using single-quotes... Try this Code:
sed "s/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/`date +"%Y-%m-%d"`/g" e123Last edited by elixir_sinari; 06-13-2012 at 04:31 AM.. |
| The Following User Says Thank You to elixir_sinari For This Useful Post: | ||
midhun19 (06-13-2012) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
when i echo a line and pipe it to sed...its working
> echo "1,parameter 2012-06-10" | sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/'`date +"%Y-%m-%d"`'/g' 1,parameter 2012-06-13 but when i use the file like cat sample.txt | sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/'`date +"%Y-%m-%d"`'/g' or sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/'`date +"%Y-%m-%d"`'/g' sample.txt its not working ---------- Post updated at 05:27 AM ---------- Previous update was at 05:24 AM ---------- can you please tell me, how to distinguish a dos format file and a unix format... the file which im using is created by vi editor in unix |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Execute the following command: Code:
dos2unix sample.txt If the file is in dos format it will be converted to unix format |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| replace (sed?) a string in file with multiple lines (string) from variable | jforce | Shell Programming and Scripting | 2 | 09-15-2011 10:10 AM |
| awk - replace number of string length from search and replace for a serialized array | otrotipo | Shell Programming and Scripting | 1 | 07-10-2009 12:04 PM |
| Search, replace string in file1 with string from (lookup table) file2? | gstuart | Shell Programming and Scripting | 9 | 06-08-2009 06:11 AM |
| Search for a string and replace the searched string in the same position in samefile | ganesh_248 | UNIX for Dummies Questions & Answers | 27 | 03-23-2009 12:35 AM |
| Search for a string and replace the searched string in the same position | ganesh_248 | Shell Programming and Scripting | 15 | 02-09-2009 08:35 PM |
|
|