如何从TAB分隔的字符串中选择第一列?
# echo "LOAD_SETTLED LOAD_INIT 2011-01-13 03:50:01" | awk -F'\t' '{print $1}'
上面的代码将返回整行,而不仅仅是返回“ LOAD_SETTLED”。
更新:
我需要更改选项卡中第三列的分隔值。以下无效。
echo $line | awk 'BEGIN { -v var="$mycol_new" FS = "[ \t]+" } ; { print $1 $2 var $4 $5 $6 $7 $8 $9 }' >> /pdump/temp.txt
但是,如果分隔符是逗号而不是制表符,则可以按预期工作。
echo $line | awk -v var="$mycol_new" -F'\t' '{print $1 "," $2 "," var "," $4 "," $5 "," $6 "," $7 "," $8 "," $9 "}' >> /pdump/temp.txt