Sample Header Ad - 728x90

How to grep between words in a log?

2 votes
4 answers
245 views
I have a txt file with lines like below. Starting With: Parameters: {"raw_message"=>"MSH....... Ending With: "} I'm wanting to grep and output to a file the words between raw and transformed which appears halfway through each line. The file appears like below Parameters: {"raw_message"=>"MSH....... "transformed_data"....."} Parameters: {"raw_message"=>"MSH....... "transformed_data"....."} Parameters: {"raw_message"=>"MSH....... "transformed_data"....."} Parameters: {"raw_message"=>"MSH....... "transformed_data"....."} Best case scenario The MSH following the >MSH begins the output but there are many MSH instances in each line. So i figured it could be logical to grep the between message and then rip the raw and transformed part out. raw_message"=>"MSH......preceding words followed by transformed Some possible words preceding transformed LAB\r", "transformed 00355", "transformed So I'd want MSH....LAB\r MSH....00355 Any assistance would be much appreciated! I tried: sed -n "//,//p" HL7prod.txt > HL7prod2.txt Example Line Parameters: {"raw_message"=>"MSH|^~\\&||CDFGTL|||20144543000||ATG^A05|TLGTADM.1.13773085|P|2.1\rEVN|A08|11111111111|||MDFGQ8833^HLPS^GEGES^^^^\rPID|1||K11111111|K1111111|HOLVBVFS^LGDSA^^^^||19GHYSSD|F|^^^^^||^^^^^^^^|||||||K01045435547691\rPV1|1|P|K.ER^^||||LKIJK^Liujn^Jeggrs^H^^^MD|||ER||||||N||ER|||||||||||||||||||||DFLHL|ABD DFIN|PRE|||111111111||||||||\rZCS||^^^^||||00355", "transformed_data"=>"|^~\\&CDFLHCOCTL201506331000ADTA08TLGGBGM.1.13773076P2.1A08201506125500MDHYQ6633LUJKLJYTEDFG1K0567432372K5894336HOLDFGEERAAAAS1111111111FK01013333333331PK.ERJTOLOKSLdasfsJtuygikdHMDERNERCOTOLAABD XXXXPRE111111111111111COTYULCDFTLK.ER"} Would Want: MSH|^~\\&||CDFGTL|||20144543000||ATG^A05|TLGTADM.1.13773085|P|2.1\rEVN|A08|11111111111|||MDFGQ8833^HLPS^GEGES^^^^\rPID|1||K11111111|K1111111|HOLVBVFS^LGDSA^^^^||19GHYSSD|F|^^^^^||^^^^^^^^|||||||K01045435547691\rPV1|1|P|K.ER^^||||LKIJK^Liujn^Jeggrs^H^^^MD|||ER||||||N||ER|||||||||||||||||||||DFLHL|ABD DFIN|PRE|||25679506645657||||||||\rZCS||^^^^||||00355
Asked by Jeff (27 rep)
Jun 13, 2015, 01:40 PM
Last activity: Aug 28, 2024, 02:35 PM