Consider a text file with scientific data, e.g.:
5.787037037037037063e-02 2.048402977658663748e-01 1.157407407407407413e-01 4.021264347118673754e-01 1.736111111111111049e-01 5.782032163406526371e-01
How can I easily delete, for instance, every second line, or every 9 out of 10 lines in the file? Is it for example possible with a bash script?
Background: the file is very large but I need much less data to plot. Note that I am using Ubuntu/Linux.
I would recommend that you do a Ctrl+F (PC) Command+F (Mac) find all "Ref" and replace with empty string (in other words leave the replace box empty). Hit enter and all done! Hope this helps!
This is easy to accomplish with awk.
Remove every other line:
awk 'NR % 2 == 0' file > newfile
Remove every 10th line:
awk 'NR % 10 != 0' file > newfile
The NR variable in awk is the line number. Anything outside of { } in awk is a conditional, and the default action is to print.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With