hans

hans

【Shell】Batch replace or delete content in files


Modify the same content in a large number of files

find -name \*.xml | xargs perl -pi -e 's|Original Content|Modified Content|g'

After using this method, there may be a problem of missing files, I don't understand why. I found the missing files one by one and pasted them back, and it prompted that the files were still in this folder, just invisible.

Modify a large amount of the same content in a document

sed -i "s/Original Content/Modified Content/g" train.txt

Delete the first few characters of a document

sed -i 's/^.....//g' file.txt Delete the first 5 characters of all lines, based on the number of dots.

sed -i 's/.....$//g' file.txt Delete the last 5 characters of all lines, based on the number of dots.

Delete lines that contain certain content

sed -i '/Content to Include/d' file.txt

Replace certain content in matching lines

sed -i '/Matching Content/s/Original Content/Modified Content/g' filename
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.