Awk consider double quoted string as one token and ignore space in between

前端 未结 7 968
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 17:26

Data file - data.txt:

ABC \"I am ABC\" 35 DESC
DEF \"I am not ABC\" 42 DESC

cat data.txt | awk \'{print $2}\'

will re

相关标签:
7条回答
  • 2020-12-15 18:18

    Yes, this can be done nicely in awk. It's easy to get all the fields without any serious hacks.

    (This example works in both The One True Awk and in gawk.)

    {
      split($0, a, "\"")
      $2 = a[2]
      $3 = $(NF - 1)
      $4 = $NF
      print "and the fields are ", $1, "+", $2, "+", $3, "+", $4
    }
    
    0 讨论(0)
提交回复
热议问题