sed - delete everything until the first digit comes up


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - delete everything until the first digit comes up
# 1  
Old 07-23-2010
sed - delete everything until the first digit comes up

Hi,

I have a text file with content as follows:

Code:
bla foo3200492
comment on this: 3900302
here comes the teddy 12

all I need is:
Code:
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 use it very barely so I would appreciate if anyone can help me here :-)
# 2  
Old 07-23-2010
Hi

Code:
sed 's/[^0-9]*//' file

Guru.
These 2 Users Gave Thanks to guruprasadpr For This Post:
# 3  
Old 07-23-2010
tr command?

Code:
echo "blah blah 1234" | tr -d [:alpha:]

would remove all of the characters
Code:
echo "blah blah 1234" | tr -cd [:digit:]

would remove anything but digits
# 4  
Old 07-23-2010
Quote:
Originally Posted by mcW

So I need the correct "sed" command to delete everything until the first number.
If you only need delete everything until the first number, guruprasadpr's code is enough.

but from your sample file, seems you need output last column. you can try this:

Code:
awk '{print $NF}' urfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed command that deletes lines with 3-5 digit strings

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)
Discussion started by: kalpcalp
3 Replies

2. Shell Programming and Scripting

problem using pattern with two digit in sed

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)
Discussion started by: babom
5 Replies

3. Shell Programming and Scripting

How to delete only the last digit in string

Hello, I would like to convert this string KBL3TEST1 into KBL3TEST How can i code this? Any help is appreciated regards, blashyou (6 Replies)
Discussion started by: blashyou
6 Replies

4. Shell Programming and Scripting

convert two digit in to single digit...

Hi Guys. My Input: ABCD 12 00 KL ABCD 12 08 DL ABCD 12 10 KK ABCD 12 04 LL ABCD 13 00 LP ABCD 13 1O LS Output: ABCD 12 0 KL ABCD 12 8 DL ABCD 12 10 KK ABCD 12 4 LL ABCD 13 0 LP (2 Replies)
Discussion started by: pareshkp
2 Replies

5. Shell Programming and Scripting

how to delete the line if the first letter is a single digit

Hi, I'm trying to acheive the following, I have a dat file in which i have several addresses, If the address starts with a single digit then i have to delete the line, if it starts with 2 or more digits then i have to keep the line Here is a sample of my file: 377 CARRER DE LA... (5 Replies)
Discussion started by: ramky79
5 Replies

6. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

7. Shell Programming and Scripting

Place digit in front of the line searching pattern using sed command

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)
Discussion started by: krbala1985
9 Replies

8. Shell Programming and Scripting

script to delete one digit.

Hi User, I have a text file with a lot of customer records (over 10,000). Each record contained one field called "charge" and it must start with some space (each record may have 15 space, 17 spece, 9 space,etc, then start with <charge> and end with </charge>, in between is a value. How can I... (3 Replies)
Discussion started by: happyv
3 Replies

9. Shell Programming and Scripting

how to delete 2 digit

I have string like abcdefgh i want to delete first two digit of the string. output should be cdefgh plz give me solution (3 Replies)
Discussion started by: Gopal_Engg
3 Replies

10. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies
Login or Register to Ask a Question