Apparently your sed doesn't understand the [[:digit:]] class, but if it did, it would replace the first digit -- the 1 in 1989 -- and replace it with a literal string "[[:digit:]]". You need to supply more context; and, apparently, use the old-fashioned [0-9] construct for matching a digit.
The regular expression matches a single digit after an underscore, and captures it into a backreference so you can refer to it as "\1" in the substitution part. (That's what the backslashed parentheses are for. Your sed might want them without backslashes, or something.) The /g at the end says to do this as many times as possible ("globally"), not just on the first occurrence.
Apparently your sed doesn't understand the [[:digit:]] class, but if it did, it would replace the first digit -- the 1 in 1989 -- and replace it with a literal string "[[:digit:]]". You need to supply more context; and, apparently, use the old-fashioned [0-9] construct for matching a digit.
The regular expression matches a single digit after an underscore, and captures it into a backreference so you can refer to it as "\1" in the substitution part. (That's what the backslashed parentheses are for. Your sed might want them without backslashes, or something.) The /g at the end says to do this as many times as possible ("globally"), not just on the first occurrence.
Thanks Era,
Your approach looks simple, but not quite right. Shamrock's method below looks long, but it gives me a right answer.
Like I have below string
XX_49154534_491553_201_122023_D
XX_49159042_491738_201_103901_D
and the expected output would be
0154534
0159042
XX and 49 can be dynamic. (1 Reply)
Hello!
My final exam in my Linux class is tomorrow, and I was just reviewing the grep and sed commands. I came across an example, by which I got stumped: it asks to provide a sed command that deletes all lines that contain exactly 3 to 5 digit strings, from a file.
In this case, I created a... (3 Replies)
Hi,
I am trying to create a csv from a existing flat file.I am using the same data to create the csv file. But I have issues \10 columns onwards..
sed... (5 Replies)
hi All,
i want to add the single digit front of the line in the report file and string compare with pattern file.
patter file: pattern1.txt
pattern num
like 4
love 3
john 2
report file: report.txt
i like very much
but john is good boy
i will love u
so after execute... (9 Replies)
Hi,
I have a text file with content as follows:
bla foo3200492
comment on this: 3900302
here comes the teddy 12
all I need is:
3200492
3900302
12
So I need the correct "sed" command to delete everything until the first number.
I am not a regex expert, because I have to... (3 Replies)
I have a var storing date
var=`date`
Now the date is returned as
Mon Feb 2 00:25:48 PST 2009
Is there any way to check the date field alone ("2" in above case) and if its a single digit then add a prefix 0 to it and store the result in same variable "var"
My intention in above case is... (3 Replies)
Hi All,
How can i convert a number 24 to 0024
In the same way how can i convert 123 to 0123?
All this has to be done inside a script
Thanks in advance
JS (6 Replies)
I found below script to check whether the variable is a digit in ksh.
############################
#!/bin/ksh
REPLY="3f"
if ]*\)'` != ${REPLY} && "${REPLY}" != "0" ]]
then
print "is digit\n"
else
print "not digit\n"
fi
############################
Although it works fine, but... (6 Replies)