HI,
I want to know can multiple pattern be given inside a sed statement..
Input:
aa_bb_cc.Mar-22-2007
cc_dd_ee.Mar-21-2007
aa_1002985_952.xml
aa_bb_032207.txt
aa_bb_cc_10002878.dat
Output:
aa_bb_cc
cc_dd_ee
aa.xml
aa_bb.txt
aa_bb_cc.dat
I got this command from Ghostdog
sed 's/_[0-9]\{1,\}//g' file > newfile
which removes the numerals following _
Is there a way to specify another pattern within the same above said sed command to remove Mar-22-2007 to get the output as mentioned above....
Thanks for you help,
Kumar.
anbu23
March 23, 2007, 2:26am
2
sed 's/_[0-9]\{1,\}//g;s/\..*-[0-9]\{1,\}$//' file
Hi Anbu,
i'm sorry,i specified the wrong input..
Input:
aa.bb_cc.Mar-22-2007
aa.dd_ee.Mar-21-2007
aa.bb_cc_ee.Mar-22-2007
aa_1002985_952.xml
aa_bb_032207.txt
aa_bb_cc_10002878.dat
Output:
aa.bb_cc
aa.dd_ee
aa.bb_cc_ee
aa.xml
aa_bb.txt
aa_bb_cc.dat
can you please give me a modified sed command...
Jacoden,
I did try out your command but it is giving the same input file as output...its not filtering out anything...
Thanks for you help guys,
Kumar.
anbu23
March 23, 2007, 2:57am
5
kumarsaravana_s:
Hi Anbu,
i'm sorry,i specified the wrong input..
Input:
aa.bb_cc.Mar-22-2007
aa.dd_ee.Mar-21-2007
aa.bb_cc_ee.Mar-22-2007
aa_1002985_952.xml
aa_bb_032207.txt
aa_bb_cc_10002878.dat
Output:
aa.bb_cc
aa.dd_ee
aa.bb_cc_ee
aa.xml
aa_bb.txt
aa_bb_cc.dat
can you please give me a modified sed command...
Jacoden,
I did try out your command but it is giving the same input file as output...its not filtering out anything...
Thanks for you help guys,
Kumar.
sed 's/_[0-9]\{1,\}//g;s/\.[a-zA-Z]\{3\}-[0-9]\{2\}-[0-9]\{4\}$//' file
Thanks a lot Anbu....It is working perfectly fine...Can you please explain me the second pattern...
Thanks and Regards,
Kumar
anbu23
March 23, 2007, 3:19am
7
kumarsaravana_s:
Thanks a lot Anbu....It is working perfectly fine...Can you please explain me the second pattern...
Thanks and Regards,
Kumar
s/\.[a-zA-Z]\{3\}-[0-9]\{2\}-[0-9]\{4\}$//
.
is a regular expression character which matches any single character except NUL.But we want to match dot in the input so we used \ to turn off the special meaning of the dot.
[a-zA-Z]\{3\}-
matches three alphabetic character followed by hypen
[0-9]\{2\}-
matches two digits followed by hypen
[0-9]\{4\}
matches four digits
$
match the preceding regular expression at the end of the line
s/\.[a-zA-Z]\{3\}-[0-9]\{2\}-[0-9]\{4\}$//
removes the string matching this regular expression at the end of line