Can we give multiple patterns to a sed command???

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.

sed 's/_[0-9]\{1,\}//g;s/\..*-[0-9]\{1,\}$//' file

Give a try on this...

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

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