首页 > 解决方案 > AWK How to extract substrings from from a variables position and different separator?

问题描述

My input is a file with a thouthans of lines like this:

|0401549244492||20210319163253|1080|0||||||{"key":150,"value":"DLO"},{"key":154,"value":"249920"}
|040148992444924||20210319163253|1080|0||||||{"key":150,"value":"DLO"},{"key":154,"value":"446910"}

Positions arent the same.. i need extract strings inside of "" ex: DLO and 5492444924 (from keyy 150 and key 155..) and extract strings between | .. its hard for me the firts.. i need make a file with these strings but without | either key word or : or "".. none of these

i need this, with same positions and fill with 0.

0401549244492002021031916325310800DLO249920 

0401489924449242021031916325310800DLO446910

A lot of thanks!

标签: stringawksubstringextract

解决方案


I am assuming that the last 2 rows is the expected output? If so, you can try this awk but I do not fully understand the request.

awk -F"[}|,\":]" '{print $2 $4 $5 $6 $15 $20}'

04015492444922021031916325310800DLO249920
0401489924449242021031916325310800DLO446910

推荐阅读