Village
Village

Reputation: 24363

How to delete lines containing only numbers in BASH?

I have a TXT file. How can I delete only those lines which only contain numbers. For e.g.:

This has some text.
1300
This has some more text.
1210
This has a text and some numbers. 12

In the sample above, only lines 2 and 4 would be deleted as they are the ones that contain no other symbols besides numbers.

Upvotes: 3

Views: 6115

Answers (3)

streamofstars
streamofstars

Reputation: 845

Sed solution (will overwrite the file):

sed -i '/^[[:digit:]]*$/d' filename.TXT

Upvotes: 0

squiguy
squiguy

Reputation: 33370

Here is an awk solution:

awk '! /^[0-9]+$/' input.txt

Upvotes: 3

Mikhail Vladimirov
Mikhail Vladimirov

Reputation: 13890

Use grep:

grep -v -E '^[0-9]+$' < source.txt > destination.txt

Upvotes: 2

Related Questions