How to make sed read its script from a file?

sed, unix

Solution

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

Problem

Recently I came across following grep command: ``` /usr/xpg4/bin/grep -Ff grep.txt input.txt > output.txt ``` which as per my understanding means that from input.txt, grep the matter contained in grep.txt and output it to output.txt. I want to do something similar for sed i.e. I want to keep the sed commands in a separate file (say sed.txt) and want to apply them on input file (say input.txt) and create a output file (say output.txt). I tried following: ``` /usr/xpg4/bin/sed -f sed.txt input.txt > output.txt ``` It does not work and I get the following error: ``` sed: command garbled ``` The contents of files mentioned above are as below: sed.txt ``` sed s/234/acn/ input.txt sed s/78gt/hit/ input.txt ``` input.txt ``` 234GH 5234BTW 89er 678tfg 234 234YT tfg456 wert 78gt gh23444 ```

Original source