简体   繁体   English

用于多个条件的AWK命令可打印不同的列

[英]AWK command for Multiple Conditions print different columns

I receive multiple files and I need to extract certain fields from all these files. 我收到多个文件,并且需要从所有这些文件中提取某些字段。 Two types of files that I receive as input, sample contents below: 我收到两种文件作为输入,下面是示例内容:

File 1 档案1

Line 1: ST*835*0001~
Line 2: ABC*I*K*KI*330.33*C*AED*CCP*01*071000013*DA*645906447*1752578509

File 2 文件2

Line 1 : ST|835|0103~
Line 2 : ABC|I|330.33|C|01|

Below is my script, 以下是我的脚本,

for file in "$SEARCH_DIR"/*; do
   recamt=$(awk -F'[|*]' '/ABC/{print $4}' $file)
    echo " $recamt " >> $logFile
done

I need to print the value 330.33 based on ABC but since the columns vary (file 1 is on column 4, file 2 is column 3 ), I am not getting the expected output... How do I achieve this ? 我需要基于ABC打印值330.33 ,但是由于各列有所不同(文件1在列4上,文件2在列3上),我没有得到预期的输出...我如何实现这一点? Thank you! 谢谢!

I also have another awk which uses as below 我也有另一个awk ,使用如下

filedate=$(awk -F'*' '/\*HP\*IRX\*/ {print $5}' $file)

How would I add the additional condition for awk -F"|" 如何为awk -F"|"添加附加条件 along with "*" but searching for "'/\\*HP\\*IRX\\*/" and "'/\\|HP\\|IRX\\|/.. Hope I am clear. Thank you! 以及"*"但搜索"'/\\*HP\\*IRX\\*/""'/\\|HP\\|IRX\\|/..希望我很清楚。谢谢!

这是一个单行代码: awk -F'[|*]' '{if($3==330.33) print "/ABC/"$3}' ./* >> logFile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM