Solved sed -i does not work

bagas

Well-Known Member

Reaction score: 9
Messages: 292

Hello.
sed -i does not work
How do I delete or replace the same in file?
Linux sed -i '/pass/d' files.txt it work.
 
OP
bagas

bagas

Well-Known Member

Reaction score: 9
Messages: 292

sed -i '' -e '/pass/d' files.txt In system FreeBSD it work.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,700
Messages: 39,300

FreeBSD's sed(1) requires an argument to -i. On Linux's sed(1) that argument is optional.

sed -i '' ... works on both Linux and FreeBSD.
 
OP
bagas

bagas

Well-Known Member

Reaction score: 9
Messages: 292

Code:
#!/bin/sh
TM=`date +"%H-%M"`
DOM=`cat /mnt/test_dom`
for f in $DOM
do
        if curl -Is --connect-timeout 5 https://$f 2>/dev/null; then
        else
            echo "Domain "$f" block, time ${TM}." | mail -s "Domain "$f" block, time ${TM}." [EMAIL]local@mail.local[/EMAIL]
            sed -i '/$f/d' /mnt/test_dom
        fi
done
exit 0
Sed does not work.
Domain is not removed from the list (/mnt/test_dom).
 

Zirias

Son of Beastie

Reaction score: 1,698
Messages: 2,869

Nope, your syntax is still wrong. The examples given in this thread are correct. But to understand what the (required) parameter to -i does, just read the manpage. That's what theses pages are written for…
 
OP
bagas

bagas

Well-Known Member

Reaction score: 9
Messages: 292

Nope, your syntax is still wrong. The examples given in this thread are correct. But to understand what the (required) parameter to -i does, just read the manpage. That's what theses pages are written for…
The old script was mistaken.
sed -i '' -e '/$f/d' /root/test_dom
I don’t understand why it doesn’t work
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 12,700
Messages: 39,300

The $f variable is in single quotes, thus it's not getting expanded but taken verbatim. There is a difference between "$f" and '$f':
Code:
#!/bin/sh

FOO="bar"
echo "$FOO"
echo '$FOO'

This is shell scripting 101.

 

Erichans

Member

Reaction score: 66
Messages: 81

chrbr

Aspiring Daemon

Reaction score: 369
Messages: 896

In my opinion it is misleading to have the words "quoting" and "simple" in one sentence :-/. From my perspective users who have no issues with quoting have reached the status of a guru. At least.
 
Top