$ echo "${BASH_VERSION}" 5.1.4(1)-release
Linux 5.18.0-17.1-liquorix-amd64 x86_64 GNU/Linux
I have a string export LIBVIRT_DEFAULT_URI='qemu:///system'
that I want to find in a user's ~/.profile
and delete the entire line. I don't know a good way to do it. Normal use of sed or awk fails with errors and sadly I'm either too dumb or too lazy (or too both) to divine how to fix it.
Where $1
would be the filename and $2
is the string to search for. These things below normally work but seem to crap out in certain situations.
This doesn't work: awk "!/$2/" "$1" > "$1".tmp && mv "$1".tmp "1"
Neither does this: sed -i "/$2/d" $1
Nor this: awk -vLine="$2" "!index($0,$2)" file
Any advice and / or direction is appreciated. I really don't wanna use Perl if I don't have to but at this point I'll take whatever bitter pill that works. Thanks.
grep -Fvx "$2" "$1"
would also work. – tripleee Oct 31 '22 at 19:21grep -Fvx "$2" "$1"
doesn't work for values of$2
that start with-
(also for values of$1
with GNU grep). – Stéphane Chazelas Oct 31 '22 at 19:25-e
option, as such. I think we can require the user to supply a path in$1
(like./-filename
) if the relative path starts with a dash. – tripleee Nov 01 '22 at 05:11export LIBVIRT_DEFAULT_URI='qemu:///system'
into a sourced function only returns the wordexport
." -- this doesn't make any sense without knowing what the function does, and you haven't shown that here. Nor what it is you're trying to do anyway. – ilkkachu Nov 01 '22 at 14:19