Use the OFS output field separator to tell awk to use colons (:) to separate fields in the output. Whereas, when we decrease the value of NF, all the fields with identifiers greater than the value are ignored. awkは入力として受け取った文字列に対して、フィールド区切り文字やレコード区切り文字を指定して、 「列」に対する処理を行うためのコマンドです。また、awk単体としても、1つのプログラムです。 … Below example can be helpful to understand its functioning. Awk variable NF defines the number of fields if the current record ( $0 ). awk可以定义输出的分隔符,其中默认的输出分隔符OFS为空格。下面通过例子简单的介绍下OFS的应用。1、echoaaabbbccc|awk-vOFS=|{print$0}aaabbbcccechoaaabbbccc|awk-vOFS=|{$1=$1;print$0}aaa|bbb|ccc通过上面的例子可以发现的 i*****love*****you . } { NF=NF; print NF,$0}' 结果 1.abc . Prepare awk to use the FS field separator variable to read input text with fields separated by colons (:). OFS is inbuild command in awk. Set a counter to 0 (zero). OFS(Output field separator) is built in variable for awk language, by default it is set to space and normally using for formatting output of a file. If we try to increase the value of NF, awk adds additional fields separated by the delimiter value in OFS.

I have a file file.txt abc : def : ghi jkl : mno: pqr stu : vwx :yzz code i used: awk -F ":" 'BEGIN {OFS=&quo | The UNIX and Linux Forums 其实OFS还有一个例子 echo "abc" | awk '{ OFS="."

Set the second field of each line of text to a blank value (it’s always an “x,” so we don’t need to see it). awk 'BEGIN{ FS="----";OFS="*****" }{ print $1,$2,$3 }' filename.