d2jsp
Log InRegister
d2jsp Forums > d2jsp > General Help > How Can I Remove Every 3rd Line Of A Text-file?
Add Reply New Topic
Member
Posts: 11,269
Joined: Jul 12 2019
Gold: 0.02
Warn: 80%
Feb 4 2022 10:30am
i got a text file (.txt) filled with names (1 name per line)
but in every 3rd line there is random text which i want to be removed.

how can i do this? the random text is always different for each 3rd line so i cannot do a simple filter trick
Member
Posts: 8,433
Joined: Nov 22 2008
Gold: 2,862.00
Feb 4 2022 10:56am
Here's a method for this in Linux terminal.

Quote
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.
Member
Posts: 17,000
Joined: Oct 24 2010
Gold: 0.00
Warn: 30%
Feb 4 2022 11:05am
windows 10 via notepad++
simply use regular expressions

Code
(?:[^\r\n]+\R){2}\K[^\r\n]+(?:\R|\z)

find this and replace it with
Code
$1


make sure you hit the "Replace All" button & check "Regular expression"

Member
Posts: 11,269
Joined: Jul 12 2019
Gold: 0.02
Warn: 80%
Feb 4 2022 11:20am
Quote (citric @ 4 Feb 2022 19:56)
Here's a method for this in Linux terminal.


Quote (OnChair @ 4 Feb 2022 20:05)
windows 10 via notepad++
simply use regular expressions

Code
(?:[^\r\n]+\R){2}\K[^\r\n]+(?:\R|\z)

find this and replace it with
Code
$1


make sure you hit the "Replace All" button & check "Regular expression"

https://imgur.com/tu7o1tc.png


thanks it's working !! :thumbsup:
Go Back To General Help Topic List
Add Reply New Topic