Reputation: 3
How can I use sed
or tr
or replace
to replace the string I get from pipe like:
head -n 1 myfile | sed -i 's/'-'/leg/g' new.log
Upvotes: 0
Views: 2471
Reputation: 195039
try this:
MY_PAT=$(head -n 1 myfile)
sed -i "s/$MY_PAT/leg/g" new.log
or
sed -i "s/$(head -n 1 myfile)/leg/g" new.log
if your myfile
contains special characters, better give concrete example.
Upvotes: 1
Reputation: 43057
use the read
shell builtin to get the first line from stdin.
#!/bin/bash
read TO_REPLACE
head -n 1 myfile | sed -i "s/$TO_REPLACE/leg/g" new.log
Upvotes: 0