Hi,
One of the scripts creates logs in the format:
progname_file1.log.20100312020657
where after file the number could be from 1 to 28 and after log. the date is attached in the format YYYYMMDDHHMISS
progname_file<1-28>.log.YYYYMMDDHHMISS.
Now I want to discard the .20100312020657 part from the string. Can your give me a command using sed with regular expressions that can to this?
i/p-progname_file1.log.20100312020657
o/p-progname_file1
Thanks in advance.
-dips
You try the following code.
sed -r 's/(.*[1-28])\.log\..*/\1/' <filename>
$ echo progname_file1.log.20100312020657|sed 's/\.[0-9].*//'
progname_file1.log
$ echo progname_file1.log.20100312020657|sed 's/\..*//'
progname_file1
> filename=progname_file1.log.20100312020657
> echo ${filename%.*}
progname_file1.log
Scrutinizer & Franklin52 both of your codes worked.
Vivekraj your code drops ".log" also.
Thanks to all of you for your time. One more request - Can anyone of you send me a link to understand the use of regular expressions with sed? I really want to learn. I have encountered two links in this forum:
1) Sed - An Introduction and Tutorial - doesn't cover regular expressions with sed totally.
2) SED and Regular Expressions - its a bit tough to comprehend.
-dips
sed_tutorial
sed
Please go through the above URL
Hi dips_apg,I have dropped .log because you have given some sample input and output.If you want it,try this.
sed -r 's/(.*[1-28]\.log)\..*/\1/' <filename>
my mistake vivekraj! I intend to keep .log too. Thanks for the solution.
Thanks thillai_selvan for the tutorial links.
-dips