Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • without knowing the input, how are we supposed to answer this? Commented Oct 20, 2022 at 10:15
  • 1. Yes, awk can print a subset of the fields from an input line. If you want a detailed answer, you'll have to provide details about exactly what you want, including sample input and output. 2. If you're using awk, you don't need to use grep. In almost all cases, piping grep's output into awk is a Useless Use Of Grep. awk can do ERE matching (like egrep/grep -E). e.g. awk -F, '/PROTO=TCP/ {for(i=1;i<=NF;i++){if($i=="SRC"){print $i}}}' Commented Oct 20, 2022 at 10:15
  • BTW, what do you mean by "but I do not know how to add the date at the beginning?" ? does the log file not have date & time field(s)? If not, what date/time do you want to print? Commented Oct 20, 2022 at 10:19
  • Apologies for the confusion, hopefully the above makes more sense Commented Oct 20, 2022 at 10:37
  • Perl? Raku? If you eventually need to produce ISO-8601 format, you could save some coding effort. iso.org/iso-8601-date-and-time-format.html Commented Oct 20, 2022 at 12:48