简体   繁体   中英

How to remove a string from file in mac terminal

I have a file with million records and each line ends with SYSTEM;\\N .

I want to delete all occurrences of ;\\N from file. How can I approach this?

You can use the sed command to replace all the occurrences of the ';\\N' from the file and replace it with ''.

sed -i 's/original/new/g' file.txt

Explanation:

sed = Stream EDitor

-i = in-place (ie save back to the original file)

The command string: s = the substitute command

original = a regular expression describing the word to replace (or just the word itself)

new = the text to replace it with

g = global (ie replace all and not just the first occurrence)

file.txt = the file name

这终于奏效了sed -i '' 's/;\\\\N//g' test112.csv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM