I am writing a script to capture conents of a file starting from a regular expression till end of the file. When I execute sed -n '/2010/,$p' filename
I can get correct output. Now I wanted date part so I did this
sed -n '/2010\/04\/27/,$p' filename
Everything is fine till here. But as soon as I try to put the date in variable and use with sed it doest work. The date variable will not have characters escaped. My question is how can I put date in a variable and use sed to capture content of file starting from the date till end of the file
for example var1=2010/04/27
now i want to print content of my file starting $var1 till end of file ..please help
Thanks guys but i still have a problem. The value of variable var1 in the given example is not known and can differ with each execution. This variable will have a date value which will be something like var1="2010/04/27"
Therefore I can not use escape charcter since value will not be known.
Is there any way i can use delimeter other than / in sed ? i tried with may characters but it doesnt work.
I read about delimiteres prior to posting here and also tried but unfortunately it doesnt work. My problem looks simple but i dont have solution
I have a variable containing date as "2010/04/27" and I want to print all lines from a file where date apprears till the end of file , and I can not hardcode the value of variable since it keeps on changing
Somebody hinted at this in an earlier post. Use a different delimiter in sed. We don't need to change the format of the date, we just need to use a different delimiter in sed.
In this case we can use "X" as the delimiter. In the script \X tells sed that this is a different delimiter. The technique is described in "man sed".
Test data abc04.txt:
line 1
line 2
2010/04/27
line 3
line 4
Script:
#!/bin/ksh
var1='2010/04/27'
cat abc04.txt|sed -n "\X${var1}X,\$ p"
Output:
2010/04/27
line 3
line 4
So I used to been routine double quotes :o maybe for more than ability from the others
[root@sistem1lnx ~]# echo "This is Test" | sed "s/`echo Test`//g"
This is
[root@sistem1lnx ~]# echo "This is Test" | sed 's/`echo Test`//g'
This is Test
Single quotes prevent the shell from intrepreting backquotes like this
For second issue I suppose there is no difference between @%,;: