Deleting lines starting with spaces then non-numerals


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Deleting lines starting with spaces then non-numerals
# 1  
Old 06-16-2009
Deleting lines starting with spaces then non-numerals

I did a search but couldn't find a thread that seemed to answer this but my apologies if it has been answered before.

I have some text files and I need to remove any line that does not start with a number (0-9). In actuality every line like this starts with a 'T' (or 't') but there are a varying number of spaces from the start of the line to the first t.

Ex: ' Track 9, .....'
or
' t x y q.....'

Is there a sed or grep expression I can use to delete these lines?


Thanks in advance for any help.
# 2  
Old 06-16-2009
Hammer & Screwdriver grep command

How about
Code:
grep "^[0-9]" infile > outfile

which will copy only lines that begin with a number in 0-9 range
# 3  
Old 06-16-2009
Code:
sed '/^ *[^0-9]/d' myFile

# 4  
Old 06-16-2009
Wow, thanks for the 2 quick responses.

I tried both and wound up with blank output files. Looking back at the original file, every numeric line has 2 spaces before the numbers start....is it possible to add that into the expression? I looked for how to represent a space in regular expressions but came up with 8 or 9 different syntax...

P.S. I don't think I've ever seen the true value of consistently formatted files but I sure do now.

P.P.S. Again thanks for the help.
# 5  
Old 06-16-2009
sorry:
Code:
sed -n '/^ *[0-9]/p' myFile

# 6  
Old 06-16-2009
Thanks! It even had the added benefit of skipping blank lines, you guys are great. Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

2. UNIX for Dummies Questions & Answers

Deleting the files with spaces

Hi All, The shell script is currently using the below command to find the seven days older files from a directories and delete them. Issue occurs when the file name consists of space in them. eg: abc def 1245.txt I need to delete the files names with space also. Please help. Thanks. Below... (7 Replies)
Discussion started by: abhi_123
7 Replies

3. Shell Programming and Scripting

Deleting rows starting with a character and word

Hi, I have multiple files of same format and I want to delete the lines starting with # and The from all of them I am using egrep -v '^(#|$)' for # but unable to do for both # and The Please guide Thanks (12 Replies)
Discussion started by: bioinfo
12 Replies

4. Shell Programming and Scripting

Remove the spaces at the end of a line starting from a fixed position

I want to remove the trailing spaces at the end of each line starting from a particular position(using ksh script). For example, in the attached file, I want to remove all the spaces starting from the position 430 till the end. The space has to be removed only from the 430th position no matter in... (3 Replies)
Discussion started by: Suryaaravindh
3 Replies

5. Shell Programming and Scripting

Deleting lines not starting with numbers with sed

Title says all :p Thanks for your help (4 Replies)
Discussion started by: drbiloukos
4 Replies

6. Shell Programming and Scripting

Concatenate lines between lines starting with a specific pattern

Hi, I have a file such as: --- >contig00001 length=35524 numreads=2944 gACGCCGCGCGCCGCGGCCAGGGCTGGCCCA CAGGCCGCGCGGCGTCGGCTGGCTGAG >contig00002 length=4242 numreads=43423 ATGCCGAAGGTCCGCCTGGGGCTGG CGCCGGGAGCATGTAGCG --- I would like to concatenate the lines not starting with ">"... (9 Replies)
Discussion started by: s052866
9 Replies

7. Shell Programming and Scripting

Deleting lines that contain spaces in a txt file

I need some help deleting lines in a file that contain spaces. Im sure awk or sed will work but i dont know much about those commands. Any help is appreciated :D (7 Replies)
Discussion started by: r04dw4rri0r
7 Replies

8. UNIX for Dummies Questions & Answers

deleting white spaces in a file

Hello Guys, I am a newbie to unix. I am having a requirement. Please help me for finding a solution for this, I am having a file as mentioned below: $ cat shank ackca acackac akcajc akcjkcja akcj ckcklc I want to delete all the white spaces in this file, I tried... (2 Replies)
Discussion started by: mraghunandanan
2 Replies

9. Shell Programming and Scripting

Deleting end line spaces for along file

How can i clear all space characteres for a long file at the end of each line? (3 Replies)
Discussion started by: osymad
3 Replies

10. UNIX for Dummies Questions & Answers

deleting white spaces

How would I delete white spaces in a specified file? Also, I'd like to know what command I would use to take something off a regular expression, and put it onto another. ie. . . . expression1 <take_off> . . . expression2 (put here) . . . Any help would be great, thanks! (10 Replies)
Discussion started by: cary530
10 Replies
Login or Register to Ask a Question