Сценарий оболочки, чтобы найти вхождения слова «здесь» и только в этих строках, заменить слово «это» словом «это». Остальные остальные строки печатаются так, как они были.
Решение awk (т.е. GNU Awk в Ubuntu) может выглядеть так:
awk '{ if ( /\yhere\y/ ) gsub ( /\ythis\y/ , "that" ); print }'
\y в awk равно \b в sed, значение которого здесь @ByteCommander уже объяснил. Сравните этот пример:
$ awk '{if(/here/)gsub(/\ythis\y/,"that");print}' <<EOL
> here is this
> here is athis
> there is this
> EOL
here is that
here is athis
there is that
$ awk '{if(/\yhere\y/)gsub(/\ythis\y/,"that");print}' <<EOL
> here is this
> here is athis
> there is this
> EOL
here is that
here is athis
there is this
Решение awk (т.е. GNU Awk в Ubuntu) может выглядеть так:
awk '{ if ( /\yhere\y/ ) gsub ( /\ythis\y/ , "that" ); print }'
\y в awk равно \b в sed, значение которого здесь @ByteCommander уже объяснил. Сравните этот пример:
$ awk '{if(/here/)gsub(/\ythis\y/,"that");print}' <<EOL
> here is this
> here is athis
> there is this
> EOL
here is that
here is athis
there is that
$ awk '{if(/\yhere\y/)gsub(/\ythis\y/,"that");print}' <<EOL
> here is this
> here is athis
> there is this
> EOL
here is that
here is athis
there is this