简体   繁体   中英

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

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

File 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 ? Thank you!

I also have another awk which uses as below

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

How would I add the additional condition for awk -F"|" along with "*" but searching for "'/\\*HP\\*IRX\\*/" and "'/\\|HP\\|IRX\\|/.. Hope I am clear. Thank you!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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