Quantcast
Channel: WhizCreed
Viewing all articles
Browse latest Browse all 14

Find and replace inside huge files on Ubuntu / Linux

$
0
0

I was trying to make changes to a text file with over 9000 lines. It was a basic operation of find and replace, however, my reliable friend Sublime text editor failed to do that!! I checked my hardware stats and it showed sublime to be using 100% processing power. Odd enough that I have Intel core i5 processor with 4 gb ram but even then I had to force kill the sublime editor, I tried the same with gedit but that did not help either. After spending some time finding solution online, I found a simple command and it worked within seconds:

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

  • 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

Viewing all articles
Browse latest Browse all 14

Trending Articles