Skip to content

Instantly share code, notes, and snippets.

@fomightez
Last active December 7, 2017 20:33
Show Gist options
  • Save fomightez/f2196b6a5485ac723de5 to your computer and use it in GitHub Desktop.
Save fomightez/f2196b6a5485ac723de5 to your computer and use it in GitHub Desktop.
using sed to do find replace in a file

adapted from here

I had a huge file I wanted to find replace in and it was seeming to make Sublime Text unresponsive so I tried

sed 's/transmit 0.780000/transmit 0.97/g' <test_78.txt >test_97.txt

and it worked great. The INPUT file is test_78.txt and OUTPUT file is test_97.txt.

Generalized, it would be

sed 's/TEXT_TO_FIND/TEXT_TO_REPLACE/g' <INPUT_FILE >OUTPUT_FILE  

where the < and > are important. (I am familiar with using > in Bash for redirecting.)


Related:
https://twitter.com/UnixToolTip/status/938825502885928960

"Change the third 'apple' in each record to 'orange': sed 's/apple/orange/3' somefile"

sed 's/apple/orange/3' somefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment