Reputation: 2989
I have a csv file(1TB) of the following form:
1 hi hello
2 users badges
abc def
3 questions
4 tags
Unanswered answered
Whenever I have a string in the beginning of the line, I want to delete that line and whenever I have a number(integer) in the beginning of the line I want to retain that line. I want the output in the following format:
1 hi hello
2 users badges
3 questions
4 tags
Is it possible to achieve it using a linux command. I know it is possible to achieve this using a programming language like python but is it possible to achieve using cat and sed, etc
Upvotes: 0
Views: 74
Reputation: 258
sed '/^[^0-9].*/d' test.txt
That deletes any lines that don't start with 0-9 in file test.txt
Upvotes: 2
Reputation: 368904
Using grep
to filter lines:
$ cat > a_file
1 hi hello
2 users badges
abc def
3 questions
4 tags
Unanswered answered
$ grep '^ *[0-9]' a_file > a_file.modified
$ cat a_file.modified
1 hi hello
2 users badges
3 questions
4 tags
$ mv a_file.modified a_file
Upvotes: 0