Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I need to remove a multi-line text (contained in a file) from another text file but only the first occurrence
- I have Windows so I can use Visual Basic but I also have gnuwin32 so I can use tools like grep, sed, etc
- Therefore I need a solution using scripts that can run from command line (not c++ programs)
- I was searching for this but what I could find was grep solutions that delete all occurrences of the lines searched, and not in the order they exist in the searched multi-line pattern
- https://stackoverflow.com/questions/174472/deleting-multiline-text-from-multiple-files
- https://askubuntu.com/questions/637639/delete-multiple-lines-from-file-when-text-is-found
- The text file looks like this:
- the
- quick
- the
- brown
- quick
- brown
- fox
- jumps
- And I need to remove the lines
- quick
- brown
- fox
- And then the result will be:
- the
- quick
- the
- brown
- jumps
- I managed to find a very complicated solution:
- - transform the newlines into a special character "@"
- - read the content of the first file into a variable
- - use sed to remove the line from the second file
- - transform again the special character "@" into newline
- However this is quite a mess for very large files that can contain the "@" character
- This is my script:
- [QUOTE]cat a.txt | tr -d "\r" | tr "\n" "@" > a1.txt
- cat b.txt | tr -d "\r" | tr "\n" "@" > b1.txt
- set /p MyText=<a1.txt
- sed -e "s/%MyText%//" b1.txt | tr "@" "\n"
- pause[/QUOTE]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement