- tags
- Coding
In-place batch file manipulation
Delete the same line in many files
Let’s start by creating a simple text file with three lines. This is what it looks like:
echo "Hello\nto the\nworld" > test.txt
cat test.txt
Hello
to the
world
We use sed to remove lines in the file matching some regex. The -i.bak option ensures the file is modified in place.
sed -i.bak '/to the/d' test.txt
cat test.txt
Hello
world
We get the file with the removed line in place of our original file. The same principle applies to several files and this allows batching.
Loading comments...