I want to replace the last date pattern with the current day date
my file looks like
>cat sample.dat
1,parameter 2012-06-10
2,parameter 2012-06-10
I want in the below format
1,parameter 2012-06-11
2,parameter 2012-06-11
I tried
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/`date +"%Y-%m-%d"/g`' sample.dat
this is not working ...can any body help me
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/'`date +"%Y-%m-%d"`'/g' sample.txt
i have tried
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/'`date +"%Y-%m-%d"`'/g' sample.txt
also i tried
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$//g' sample.txt
but both showing me the same results ...
1,parameter 2012-06-10
2,parameter 2012-06-10
i think the regular expression is not correct.. please help
Check if your input file is in DOS format, it should be in Unix format.
The shell will not look at your date command which you've protected using single-quotes...
Try this
sed "s/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}$/`date +"%Y-%m-%d"`/g" e123
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
Execute the following command:
dos2unix sample.txt
If the file is in dos format it will be converted to unix format
Thanks all ...this is resolved ...actually there was additional spaces after the string and i was able to solve it using
sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}.*$/'`date +"%Y-%m-%d"`'/g' sample.txt