Hi all,
I need to extract the "abcdef" from the below string Digital_abcdef_20130103.txt.gz
The length of the "abcdef" will be changing but it will be always after the word Digital_ and before the second underscore
help in this regard is highly appreciated
RudiC
January 3, 2013, 7:06am
2
Pls read forum rules carefully and use code tags as advised!
You don't mention your system (HW/OS), you don't specify where and how your string comes from - based on wild guessing, try:
$ echo Digital_abcdef_20130103.txt.gz|sed 's:^Digital_\(.*\)_.*$:\1:'
abcdef
1 Like
Jotne
January 3, 2013, 7:53am
3
awk -F_ '/Digital/ {print $2}' infile
This sets filed separator to underscore _
and if Digital
is found, print second field $2
var=Digital_abcdef_20130103.txt.gz
var2=${var#*_}
echo "${var2%%_*}"