4

以下のようなファイルがあります。

10temp3
20/temp4
28 temp 5

以下のコマンドを使用して行を分割し、行の最後の番号を取得しています。

awk -F"temp" '{print $NF}' temp3

私が得た出力は次のとおりです。

> awk -F"temp" '{print $NF}' temp3
10temp3
20/temp4
28 temp 5

驚いたことに、nawk を使用すると、期待どおりの出力が得られます。

> nawk -F"temp" '{print $NF}' temp3
3
4
 5
> 

その理由を知ってもいいですか?awk はセパレーターとして言及されている文字列をサポートしていませんか?

4

1 に答える 1

3

Indeed Solaris awk only considers a single character. I'd say it's probably due to tradition, and exactly the reason why nawk is shipped, as well.

The -F switch is really special: it's taking the first character of your quoted string, and discarding the rest, so the t remains --- which stands for "look for tab as field separator".

于 2012-08-13T13:27:29.577 に答える