I have written a small piece of code, which it take regex expression from variable and put into sed. When I run the script I get something like this.
sed: first RE may not be empty
The script delete lines according to specifications from a variable. variable could be empty.
NR=$1
sed '/'"${NR}"'/d' in.txt > out.txt
How can I fix it or is it some better function which I can use it? :)
You can use:
# re is set to $1 or $^ if $1 is not provided
re="${1:-\$^}"
# $^ being an invalid regex will NOT delete anything
sed "/$re/d" in.txt > out.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With