I'm trying to filter some mail logs and I need to get some specific information from certain columns that are not always the same. The information can be on different columns each line. I always use awk to print only the columns I want, like:
cat file.log | awk '{print $1" "$2" "$3}' >> output.txt
but in this case, I don't know which column contains the string I'm looking for.
Example file.log where I'm looking for columns that contain the string "5":
A B C 222 586 999 724 644
A B C 510 333 987 678 633
A B C 348 488 920 566 240
Result I want:
A B C 586
A B C 510
A B C 566
Any help is appreciated
perlthen you can do$perl -pe "s/^(\D+).*\b(5\d*).*/$1$2/" your_file.txt