複数の条件を持つ grep カンマ区切りフィールド

複数の条件を持つ grep カンマ区切りフィールド

Linuxサーバーには、次のコンテンツを含む大きなテキストファイルがあります。たとえば、次のようになります。

123456789012345,00,0000,0000
1234567890123450,00,0000,000
12345678901b111,0,0000,0000
1234567/89011111,00,0000,00000

出力

12345678901b111,0,0000,0000       line# 3
1234567/8011111?,00,0000,00000    line# 4

だから私の目標は次のとおりです。

私はラインをgrepしたいと思います。

not 15 or 16 digits only before first comma
not 2 digits only before second comma
not 3 or 4 digits only before third comma
not 3 or 4 digits only after third comma

**the line should cover ANY of the predefined conditions**

各行の行番号を印刷し、別のテキストに保存します。

ベストアンサー1

AWK解決策:

awk -F, '$1!~/[0-9]{15,16}/ || $2!~/[0-9]{2}/ || $3!~/[0-9]{3,4}/ || $4!~/[0-9]{3,4}/{ 
             printf "%-35s line# %s\n",$0,NR 
         }' file
  • -F,- カンマを,フィールド区切り文字として扱う

  • printf "%-35s line# %s\n"- ソート/ソートされた形式の出力


出力:

12345678901b111,0,0000,0000         line# 3
1234567/89011111,00,0000,00000      line# 4

おすすめ記事