1.输出指定长度的字符串,位数不够时以空格补充,默认右对齐:
[tortoise@sea temp]$ awk '{printf "%50s\t%s\n",$1,$2}' test.txt fdsafdsafdsfdsfdsf fdsafdsafdsafdsre1r32r fdsafd u0t435435345 5382-4932jfermnwf rfewqre3rqewqr fdsa fewqr3241r4324 [tortoise@sea temp]$
加上-表示左对齐:
[tortoise@sea temp]$ awk '{printf "%-50s\t%s\n",$1,$2}' test.txt fdsafdsafdsfdsfdsf fdsafdsafdsafdsre1r32r fdsafd u0t435435345 5382-4932jfermnwf rfewqre3rqewqr fdsa fewqr3241r4324 [tortoise@sea temp]$
2.toupper:将字符串中的小写字符转换为大写字符:
[tortoise@sea temp]$ echo "Tortoise" | awk '{print toupper($1)}' TORTOISE [tortoise@sea temp]$ echo "torToise" | awk '{printf "%s\n",toupper($1)}' TORTOISE [tortoise@sea temp]$
3.tolower:将字符串中的大写字符转换为小写字符:
[tortoise@sea temp]$ echo "Tortoise" | awk '{print tolower($1)}' tortoise [tortoise@sea temp]$ echo "TOrToise" | awk '{printf "%s\n",tolower($1)}' tortoise [tortoise@sea temp]$