Delete a line that contains more than 1 specific string
I use '/'"$name"'/d'
for deleting the line that contains a user input name variable. But I want to delete the line that contains $name
and $surname
together. How can I modify this '/'开发者_开发技巧"$name"'/d'
code?
Can do it with sed like this :
cat input | sed '/\('"$name"'.*'"$surname"'\)\|\('"$surname"'.*'"$name"'\)/d'
easiest would be
cat input | egrep -v "$name.*$surname" | egrep -v "$surname.*$name" > output
awk '/name/ && /surname/ {next} 1' filename
or, to pass the values from the shell into awk
awk -v first=$name -v last=$surname '$0 ~ first && $0 ~ last {next} 1' filename
Ruby(1.9+)
$ ruby -ne 'next if /'"$name"'/ && /'"$surname"'/;print' file
精彩评论