The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20120913

bash regex/regexp how to remove all lines from file not matching specific text string

after struggling in the geany editor to get regex to work, i tried a different approach.

say you have a file, test.txt, with the following content:
menu2.getChildren().add(createMenuItem("none", userNorwegian ? ...
menu2.getChildren().add(createMenuItem("none", userEnglish ? ...
menu2.getChildren().add(createMenuItem("none", userNorwegian ? ...
menu2.getChildren().add(createMenuItem("none", userEnglish ? ...

but you only want a file with the lines containing the string userNorwegian, i.e. you want to remove the lines containing userEnglish.

open a terminal and run this:
sed -n 's/userNorwegian/userNorwegian/p' test.txt > out.txt

-n means:
suppress automatic printing of pattern space

p means:
Print the current pattern space.

keep it simple, stupid! ;)

thanks for the idea here:
http://stackoverflow.com/a/8255627/557194

No comments:

Post a Comment