Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

perl oneliner to read file line by line and skip some word by position

Given a log like this:

2022-03-30 21:05:00.266 +0200 CEST debug  Mylog 

is it possible to parse it (with a oneliner command) and skip, for example 3rd 4th and 5th
so that I would get this output?

2022-03-30 21:05:00.266 Mylog  

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

perl -lane 'splice @F, 2, 3; print "@F"'
  • -l removes newlines from input and adds them to output
  • -n reads the input line by line, running the code for each line
  • -a splits each line on whitespace into the @F array
  • splice removes three elements from @F starting with position 2 (numbering starts at 0)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading