I have a file with some tabular data in it. But it also has some text line(ending with a colon) in between the data. So i want to remove those text lines and only have my data.
Asked
Active
Viewed 4,205 times
2 Answers
2
you could use grep - something like
grep -v ":$" file
or sed - like
sed "/:$/d" file

Ian Kenney
- 6,376
- 1
- 25
- 44
2
Try this:
awk '{gsub(/:$/,""); print}' file.txt
This will take only the last colon and not the one which contain colon in between the line.
or as JID commented:
awk '!/:$/' file

Rahul Tripathi
- 168,305
- 31
- 280
- 331
-
and how do I get the output in a new file? Sorry for such silly question but i am kind of new to this. – Siddharth Kota Apr 23 '15 at 13:39
-
@SiddharthKota:- `awk '{gsub(/:$/,""); print}' file.txt>output.txt` – Rahul Tripathi Apr 23 '15 at 13:42
-
1@SiddharthKota:- You are welcome. However thats strange you marked the other answer as accepted and saying that this worked :) The point of accepting the answer is to make future readers having the same problem should get the answer which worked. – Rahul Tripathi Apr 23 '15 at 13:51
-
hi @RahulTripathi...i needed another small help. I want to run the above awk action on a folder containing multiple such files at once. how do I do it? – Siddharth Kota May 03 '15 at 10:54
-
@SiddharthKota:- Could you please ask a new question for that, explaining exactly what you are looking for? That would help you as well as it will attract other people's attention as well – Rahul Tripathi May 04 '15 at 05:01