Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 586
user842122 Avatar asked Sep 06 '25 03:09

user842122


2 Answers

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 (i.e. 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 (i.e. replace all and not just the first occurrence)

file.txt = the file name

like image 133
raizsh Avatar answered Sep 08 '25 16:09

raizsh


This worked finally sed -i '' 's/;\\N//g' test112.csv

like image 42
user842122 Avatar answered Sep 08 '25 16:09

user842122