title: UNIX: Extracting only the information I need
body: <p>I have the following content on a file and I need to extract certain things to another file to make the analysis easier.</p>
  
  <hr>
  
  <pre><code>saimptlogi_1~20170208022514~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4403_20170115010230_1.dat
  saimptlogi_1~20170208022549~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4189_20170122010240_1.dat
  saimptlogi_1~20170208022555~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4403_20170116010200_1.dat
  saimptlogi_1~20170208022556~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4189_20170108010210_1.dat
  saimptlogi_1~20170208022610~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4147_20170101010223_1.dat
  saimptlogi_1~20170208022643~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4189_20170107010206_1.dat
  saimptlogi_1~20170208022703~procRTLFHead~~103~RET-0103: generic function processing error~STOREDAYNOTREADYTOBELOAD on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4549_20170126010247_7.dat
  saimptlogi_1~20170208022707~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4189_20170114010259_1.dat
  saimptlogi_1~20170208022736~procRTLFHead~~103~RET-0103: generic function processing error~DATAUNEXPECTEDSTOREDAY on FHEAD record at line 0000000001 in /oretail/apprms/mmhome/data/in/RTLOG_4403_20170108010211_1.dat
  </code></pre>
  
  <hr>
  
  <p>I want to extract the error (<strong>DATAUNEXPECTEDSTOREDAY</strong> or <strong>STOREDAYNOTREADYTOBELOAD</strong>) the Store (RTLOG_<strong>4403</strong>_20170108010211_1) and the Date (RTLOG_4403_<strong>20170108</strong>010211_1) to another file and I need the output to be like this:</p>
  
  <p><strong>Example:</strong> </p>
  
  <ul>
  <li>DATAUNEXPECTEDSTOREDAY 4403 20170108 </li>
  <li>STOREDAYNOTREADYTOBELOAD 4549 20170126</li>
  </ul>
  
  <p>I've already developed a command to extract the STORE and the DATE directly from the files (RTLOGS) but it would be better to extract directly from this log file.</p>
  
  <p><strong>My Command:</strong>
  ls {RTLOG*.failed,RTLOG*.rej} | awk -F'|' '{gsub("_"," "); print substr($0,7,13), $4}'</p>
  
  <p>Thank you in advance.</p>