开发者

awk split field format

awk '{spl开发者_JAVA技巧it($2,a,"-")};
     {if ($1=="aa") {print "'$var'/"$1"/"a[1]"/"$2" '$var'/bb/"a[1]} 
      else {print "'$var'/"$1"/"a[1]"/"$2" '$var'/aa/"a[1]}}'

hi, $2 is all lower case text. I have split it and would like to output a[1] in upper case.

How can I do this ?

Tom


you can use awk's toupper(a[1])


You can avoid complex and hard to read quoting if you use AWK's variable passing. You can also make use of the Output Field Separator. Also, you have extra curly braces that you don't need.

awk -v "var=$var" 'BEGIN{OFS="/"}
  {split($2,a,"-"); a[1]=toupper(a[1])
  if ($1=="aa") {print var, $1, a[1], $2 " " var, "bb", a[1]} 
    else {print var, $1, a[1], $2 " " var, "aa", a[1]}}'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜