Как исключить этот шаблон в скриптах bash? - PullRequest
0 голосов
/ 23 апреля 2019

Я хочу сопоставить шаблон, используя SED и / или GREP, которые могут исключать некоторые алфавиты.

## This code will match the alphabet, how to exclude them?
## Here, the variable is string which we are matching.


argument=$2
grep "$(sed 's/./&.*/g' <<< "$argument")" "$file_name"
shift ;;

# Possible output

$ sh match_the_pattern.sh -c aeiou words.txt

cyts
flybs
glhs
lphs
mrhs
nmphs

# As you can see, it is posting the words but execluding the characters from given string.

1 Ответ

0 голосов
/ 23 апреля 2019

Вы имеете в виду что-то подобное?

remove_chars.sh

#!/bin/bash
sed "s/[$1]//g" "$2"

ИСПОЛЬЗОВАНИЕ:

remove_chars.sh chars file.txt

Пример:

remove_chars.sh aeiou file.txt

Внимание: Не все символы работают, но буквы и цифры!

...