I am writing a simple batch script, and I need to delete one line from the file that gets downloaded by the script. What is the easiest way to do this using ONLY the command prompt? I have come across several various suggestions, but nothing to very simply delete one string that is constant across all files that are downloaded with the script.
Asked
Active
Viewed 2,278 times
0
-
2Do you know the line content? Does it occurs only once? If so, you could try using findstr /v to create a new file without that line... – cesarse Aug 10 '15 at 14:54
1 Answers
1
This is a very platform dependant question. If you are using a *nix environment (Linux / Mac environment using bash / shell), you can accomplish this with sed
sed '/${regular_expression_that_matches_line_to_be_removed}/d' yourFile.txt > newFile.txt
This will generate a new file called newFile.txt
that will contain the output. You can also do this in place (it modifies the file it's using as input), but I recommend against that because if you mess up your regex, you've lost your input.
If you're using a Windows environment (which I assume you are due to your batch-file tag), try looking at this Delete certain lines in a txt file via a batch file
-
Yes, this is Windows. Thanks for the link. I thought there may be a different way without rewriting the file, but it will do! – jay-charles Aug 10 '15 at 15:06