Batch Script to Find Certain words and delete those lines in a file

Posted by SuperUserMan on Super User See other posts from Super User or by SuperUserMan
Published on 2014-08-16T21:04:07Z Indexed on 2014/08/23 10:24 UTC
Read the original article Hit count: 409

Filed under:
|
|
|
|

EDITED THE QUESTION as regarding type of solutions I am on Windows & some suggested SED etc. So i am OK with these 3rd party standalone exe's using command line

Say i have following lines in abc.txt file

"@yuy007 what are you doing friend #disneyrocks"
"STFU, i dont care what you think @happy55"
"@social88 @gg99 ok mate see you at the subway :)"
"btw arnold was great in that movie @tt11 @gg11 #disneyrocks"
"we are going to disney. Do you want to? #disneyrocks"
"We dont like disney.#disneyrocks we are not going" 
".@socialguy what are you upto #disneyrocks " 

I need to employ 5 filters with above file to get def.txt

  1. Delete all lines which start with @ character, like 1st and 3rd
  2. Delete all lines which start with .@ characters, like 7th
  3. Delete all lines which don't have any word starting with # like 2nd and 3rd
  4. In leftover lines, Delete all words starting with @ character (keeping the lines intact) like words @happy55 in 2nd , @social99 & @gg99 in 3rd, etc. In this case we still need to preserve quotes " at start and end of line
  5. Delete all the blank lines left after above lines are removed

EDIT if i have following line , it wrongly deletes the content after @word's

"btw arnold was great in that movie @tt101 @gb1997 #whatthehell"

is edited to

"btw arnold was great in that movie"

Thanks

© Super User or respective owner

Related posts about batch

Related posts about script