How to make sed read its script from a file?

Rather than keeping the sed commands in a separate text file, you may want to try creating a sed script. The file below can run directly on your data files:

./myscript.sed inputfile.txt > outputfile.txt

#!/bin/sed -f
s/234/acn/
s/78gt/hit/

Your sed.txt should only contain sed commands: No prefixing with sed or suffixing with an input file. In your case it should probably be:

# sed.txt
s/234/acn/
s/78gt/hit/

When ran on your input:

$ /usr/xpg4/bin/sed -f sed.txt input.txt
acnGH
5acnBTW
89er
678tfg
acn
acnYT
tfg456
wert
hit
ghacn44

Tags:

Unix

Sed