How to concat columns?

Hello All,

I have a file with following data.

1365787116     3.0    contracts/Procs_Val_Req_forContrct_Amnd_BPEL
1348791394     2.0      contracts/Procs_Val_toTerm_Ret_Contrct_BPEL
1348791394     2.0      contracts/Qualfy_BP_forNew_Ret_Contrct_BPEL
1348791394     2.0      contracts/Re_Evaluate_IME_Agreement_BPEL
1365787116     3.0      contracts/Review_Bp_Admin_Documents_BPEL
1366127683     3.1     contracts/Review_Bp_Admin_Documents_Refer_BPEL
1365787116     3.0      contracts/Review_Disability_Documents_BPEL
1348791394     2.0      CR/Service_Credit_Purchase_Appeals_BPEL
1348791394     2.0      enrollment/Member_Election_1_to_2_Tier_BPEL

I want the output in other file in such a way that it remove the first column and then all the name having version 3 or above.

Output

Procs_Val_toTerm_Ret_Contrct_BPEL[2.0]
Qualfy_BP_forNew_Ret_Contrct_BPEL[2.0]
Re_Evaluate_IME_Agreement_BPEL[2.0]
Service_Credit_Purchase_Appeals_BPEL[2.0]
Member_Election_1_to_2_Tier_BPEL[2.0]

This is simple to solve.

awk -F"[ /]+" '$2!~/^3/ {print $4"["$2"]"}' file >outfile
cat outfile
Procs_Val_toTerm_Ret_Contrct_BPEL[2.0]
Qualfy_BP_forNew_Ret_Contrct_BPEL[2.0]
Re_Evaluate_IME_Agreement_BPEL[2.0]
Service_Credit_Purchase_Appeals_BPEL[2.0]
Member_Election_1_to_2_Tier_BPEL[2.0]
1 Like

Excellent Jotne. Its time for me to learn awk deeply as it is very powerful utility. Thanks again.

Could you please explain the above?

Hi Karthikeayan,

awk -F"[ /]+"       - This is for field seperator means removing this slash sign
$2!~/^3/            - This means $2 means second column should not be starting with value 3
{print $4"["$2"]"}' - This means print 4rth column which is BPEL name together with second column which is not having 3 or 3.* value.

hi Vikram,

thanks for the quick reply. I have one question..
if $2 has the value more than 3, like 4.0... then how can we ignore that line?

This will work in that case

awk  -F"[ /]+" '$2!~/^[3-4]/ {print $4"["$2"]"}' file

This means starting from 3 to 4 it will ignore those values. Similarly you can put any which u want to ignore.

great vikram.. thanks..

-F"[ /]+"
Normal field separator is any space or tab.
[] makes possible multiple field separator
" " (one single blank) and / is then used as field separator.
Since there are more than one blank here 1365787116 3.0 con , use the + to repeat the number of field separator

This may then be a better solution

awk -F"[ /]+" '$2<3 {print $4"["$2"]"}' file

Keeps everything less then 3

1 Like