bash - Remove lines in file NOT containing characters in whitelist -


how remove lines in file containing characters not in whitelist?

whitelisted characters:

a-z a-z {}!@$%&().,;'" 

input:

the socialist government of josé sócrates of commended. allow me final comment {please} watch tom & jerry 

output:

all of commended. allow me final comment {please} watch tom & jerry 

i tried sed '/[a-za-z]{}!@$%&().,;'"/,$d' input doesn't match per character.. help?

one of weirder tricks in bash match double-negative. here, print lines not contain characters not in our list:

pat='a-z a-z{}!@$%&().,;"'"'" while read -r;   if [[ $reply != *[^$pat]* ]];     printf '%s\n' "$reply"   fi done 

this more commonly done when trying tell if value purely numeric ($var != *[^0-9]*), works here well.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -