Skip to main content
added \b for word boundaries to generated regexp. and updated the explanation.
Source Link
cas
  • 84.9k
  • 9
  • 138
  • 207
sed -E -e "s/$(aspell list <file | sort -u | paste -s -d'|' |
               sed -e 's/^/\\b(/; s/$/)\\b/' )//g" \
    file > newfile

This uses command substitution $(...) to insert the output of aspell list <$file into a sed search and replace operation.

aspell's output is also unique sorted and paste is used to join each line with |. Finally it is piped through sed to makeadd \b word-boundary anchors as well as open and close parentheses. All of which constructs a valid extended regular expression like \b(word1|word2|word3|...)\b to use as the search regexp in the sed search and replace command.

You can test itthe result of the entire command with, e.g., diff -u file newfile

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

sed -E -e "s/$(aspell list <file | sort -u | paste -s -d'|')//g" file > newfile

This uses command substitution $(...) to insert the output of aspell list <$file into a sed search and replace operation.

aspell's output is also unique sorted and paste is used to join each line with | to make a valid extended regular expression.

You can test it with, e.g., diff -u file newfile

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

sed -E -e "s/$(aspell list <file | sort -u | paste -s -d'|' |
               sed -e 's/^/\\b(/; s/$/)\\b/' )//g" \
    file > newfile

This uses command substitution $(...) to insert the output of aspell list <$file into a sed search and replace operation.

aspell's output is also unique sorted and paste is used to join each line with |. Finally it is piped through sed to add \b word-boundary anchors as well as open and close parentheses. All of which constructs a valid extended regular expression like \b(word1|word2|word3|...)\b to use as the search regexp in the sed search and replace command.

You can test the result of the entire command with, e.g., diff -u file newfile

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

changedd to use sed.
Source Link
cas
  • 84.9k
  • 9
  • 138
  • 207
grep -vsed -FE -fe <"s/$(aspell list "$file"<file | sort -u | paste -s -d'|')//g" "$file"file > "$file.new"newfile

This uses processs substitutioncommand substitution <$(...) to supplyinsert the output of aspell list "$file"<$file as an input file tointo a grepsed search and replace operation.

aspell's output is also unique sorted and -fpaste (akais used to join each line with --file|) option to make a valid extended regular expression.

OtherwiseYou can test it with, it's just standard use ofe.g., grepdiff -vu -F (print only non-matching lines, use fixed strings rather than regexps).

Use -ifile newfile if you want the search to be case-insensitive, which will be considerably slower.

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

grep -v -F -f <(aspell list "$file") "$file" > "$file.new"

This uses processs substitution <(...) to supply the output of aspell list "$file" as an input file to grep's -f (aka --file) option.

Otherwise, it's just standard use of grep -v -F (print only non-matching lines, use fixed strings rather than regexps).

Use -i if you want the search to be case-insensitive, which will be considerably slower.

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

sed -E -e "s/$(aspell list <file | sort -u | paste -s -d'|')//g" file > newfile

This uses command substitution $(...) to insert the output of aspell list <$file into a sed search and replace operation.

aspell's output is also unique sorted and paste is used to join each line with | to make a valid extended regular expression.

You can test it with, e.g., diff -u file newfile

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

added 92 characters in body
Source Link
cas
  • 84.9k
  • 9
  • 138
  • 207
grep -v -F -f <(aspell list "$file") "$file" > "$file.new"

This uses processs substitution <(...) to supply the output of aspell list "$file" as an input file to grep's -f (aka --file) option.

Otherwise, it's just standard use of grep -v -F (print only non-matching lines, use fixed strings rather than regexps).

Use -i if you want the search to be case-insensitive, which will be considerably slower.

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

grep -v -F -f <(aspell list "$file") "$file" > "$file.new"

This uses processs substitution <(...) to supply the output of aspell list "$file" as an input file to grep's -f (aka --file) option.

Otherwise, it's just standard use of grep -v -F (print only non-matching lines, use fixed strings rather than regexps).

Use -i if you want the search to be case-insensitive, which will be considerably slower.

grep -v -F -f <(aspell list "$file") "$file" > "$file.new"

This uses processs substitution <(...) to supply the output of aspell list "$file" as an input file to grep's -f (aka --file) option.

Otherwise, it's just standard use of grep -v -F (print only non-matching lines, use fixed strings rather than regexps).

Use -i if you want the search to be case-insensitive, which will be considerably slower.

AFAIK, aspell doesn't have an auto-correct mode. This is probably a Good Thing.

Source Link
cas
  • 84.9k
  • 9
  • 138
  • 207
Loading