need to delete lines that start with letters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need to delete lines that start with letters
# 1  
Old 06-04-2009
need to delete lines that start with letters

Hi,

I need to remove all lines from a file that do not start with numbers

For instance, if the first three characters on any line are not numbers, delete those lines

I've tried to do it with awk and it's not working, any ideas ?

Thanks
# 2  
Old 06-04-2009
Is this a homework question?
Assuming that it's not, what is the practical business problem you are solving?
# 3  
Old 06-04-2009
The problem is this...

We get inventory files dumped from POS systems. They are supposed to be in this format- SKU;quantity;price;location

However, one particular store has added custom SKU's to their inventory, and the SKU's they created all contain A-Z and sometimes the ' character.

I can remove the lines with the ' character using tr and the octal code for '

However, the job that loads the inventory into the DB only accepts numerics for the first field, so it is failing due to the custom SKU's they have created.

That's why I need to do something like "if the first three characters of any line are A-Z delete that line" or even "if the first three characters of any line are not 0-9 delete that line" and I need it to do it for every line in the file...

Thanks
# 4  
Old 06-04-2009
Code:
echo '1A23abn' | sed -n '/^[0-9]\{3\}/p'

This User Gave Thanks to vgersh99 For This Post:
# 5  
Old 06-04-2009
Or with grep:

Code:
grep '^[0-9][0-9][0-9]' file > newfile

# 6  
Old 06-04-2009
Both solutions worked

Thanks so much guys.

Doh, the grep one completely slipped my mind !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. UNIX for Beginners Questions & Answers

How do delete certain lines alone which are matching with start and end string values in file?

Hi, In my previous post ( How to print lines from a files with specific start and end patterns and pick only the last lines? ), i have got a help to get the last select statement from a file, now i need to remove/exclude the output from main file: Input File format: SELECT ABCD, DEFGH,... (2 Replies)
Discussion started by: nani2019
2 Replies

3. Shell Programming and Scripting

Get the average of lines with the same first 4 letters

How to sum up and print into the next line the total SUM. ]$ cat hhhh aaa1a 1 aaa1g 2 aaa1f 3 baa4f 3 baa4d 4 baa4s 4 cddg1 3 cddg3 4 cddfg 1 $ cat hhhh|awk ' {sum+=$2} END {print sum}' 25 Desire output: aaa1a 1 (13 Replies)
Discussion started by: kenshinhimura
13 Replies

4. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

5. UNIX for Dummies Questions & Answers

How can I replace the lines that start with a star and replace it with numbers start from 1?

I need to replace the (*) in the fist of a list with numbers using sed for example > this file contain a list * linux * computers * labs * questions to >>>> this file contain a list 1. linux 2. computers 3. labs 4. questions (7 Replies)
Discussion started by: aalbazie
7 Replies

6. UNIX for Dummies Questions & Answers

Grep.Need help with finding the words which start at [A-K] letters in thesecond column of the table

Hi buddies ! I need some help with one grep command :) I have this table: 1 Petras Pavardenis 1980 5 08 Linas Bajoriunas 1970 10 3 Saulius Matikaitis 1982 2 5 Mindaugas Stulgis 1990... (1 Reply)
Discussion started by: vaidastf
1 Replies

7. UNIX for Dummies Questions & Answers

How to delete all columns that start with a specific value

I have this space delimited large text file with more than 1,000,000+ columns and about 100 rows. I want to delete all the columns that start with NA such that: File before modification aa bb cc NA100 dd aa b1 c2 NA101 de File after modification aa bb cc dd aa b1 c2 de How would I... (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Shell Programming and Scripting

Start from the prefixes, delete script

My folder is/app2/istech/scratch, which contain all the below files. I need to delete the files which start from the prefixes. dup_events_*.* Event_*.* New_time_*.* New_Loc_*.* New_Uptime_*.* Detailed_Reason*.* cmt_dup_*.* Uptime_*.* Can anyone please let me know how to write a... (3 Replies)
Discussion started by: dsnaveen
3 Replies

9. Shell Programming and Scripting

Delete all lines that start with a bigger number of a specific one.

E.g. the file is like this: I want to delete all lines that begin with a number larger than 2, ignoring the lines that doesn't begin with a number! PS:'2' is actually a variable that can have a lot of values:b:i bet you got it (10 Replies)
Discussion started by: hakermania
10 Replies

10. Shell Programming and Scripting

awk - delete last two letters

Hello! How do I remove the last two letters "GB" off each line, using awk? What I need to remove is the "GB" in following input: ..... 30GB 2504GB 3GB 40GB ...... The OS used is Solaris9 Regards, Fredrik (1 Reply)
Discussion started by: sap4ever
1 Replies
Login or Register to Ask a Question