Comments on: How to Filter Text or String Using Awk and Regular Expressions – Part 1 https://www.tecmint.com/use-linux-awk-command-to-filter-text-string-in-files/ Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks. Mon, 12 Aug 2024 06:43:01 +0000 hourly 1 By: Pooja https://www.tecmint.com/use-linux-awk-command-to-filter-text-string-in-files/comment-page-1/#comment-2161747 Tue, 23 Apr 2024 08:59:11 +0000 http://www.tecmint.com/?p=19807#comment-2161747 I’ve come across many awk tutorials, but this one stands out as the best by far. It’s helped me grasp awk in a way I never thought possible. The breakdown of the awk syntax, particularly the explanation of “awk pattern action file,” is incredibly clear and concise. I’ve yet to find such clarity elsewhere. Thank you immensely for this invaluable resource.

]]>
By: aparna bl https://www.tecmint.com/use-linux-awk-command-to-filter-text-string-in-files/comment-page-1/#comment-1472126 Wed, 07 Apr 2021 13:46:50 +0000 http://www.tecmint.com/?p=19807#comment-1472126 In reply to Erik Persson.

HI Erik Persson

You are awesome. You taught me awk. No one else explained it like you. Do you teach?

]]>
By: RF Engineer https://www.tecmint.com/use-linux-awk-command-to-filter-text-string-in-files/comment-page-1/#comment-1466138 Wed, 31 Mar 2021 07:05:52 +0000 http://www.tecmint.com/?p=19807#comment-1466138 This is wonderful tutorial and very well illustrated.

There is a minor error in the explanations on what asterisk (*) means in regular expressions — it means ‘match the previous character zero or more times‘. For example 'p*' will match the letter ‘p’ zero or more times, thus this expression will match anything and everything because it will be looking for the letter ‘p’ to be contained zero or more times — and absolutely any text contains the letter ‘p’ either zero or more times.

For this reason asterisk is never used with just a single symbol before it, it must be used in an expression with more symbols inside it, like /A-*B/, which will match “A” followed by zero or more hyphens "-" and then followed by “B”, thus the following strings will produce a match “AB” (this has zero occurrences of ‘-‘), “A-B”, “A–B”, “A—B” and so on.

Note that the text presented in this tutorial erroneously suggests that /A-*B/ will not match “AB” when a simple check in AWK shows that it is matching it (in fact a test in any REGEXP application will show the same result, e.g. egrep).

For this reason this tutorial interprets somewhat erroneously the result of:

# awk '/l*c/{print}' /etc/localhost

The above will match all lines that contain the letter ‘c’ regardless whether they contain the letter ‘l’ or not. This is because /l*/ means ‘match letter l zero or more times‘, so /l*c/ means ‘match letter c preceded by zero or more occurrences of letter l‘, but any line that contains the letter c in it also contain zero or more letters l in front of it — the key to understanding this is “ZERO or more times“.

CONCLUSION: In REGEXP the asterisk symbol (*) does not mean the same thing as in Microsoft Windows and DOS/CMD file-name matching, it does not match any character (as this tutorial erroneously suggests), it matches the preceding character ZERO or more times.

]]>
By: Daniel P Fruzzetti https://www.tecmint.com/use-linux-awk-command-to-filter-text-string-in-files/comment-page-1/#comment-1166290 Tue, 11 Jun 2019 19:42:33 +0000 http://www.tecmint.com/?p=19807#comment-1166290 I’m struggling to make my script work. I have a huge file and each line needs to be searched for the string “WAP” and then, when found, the character appearing two characters BEFORE the string needs to be returned. Can you help me simplify this?

]]>
By: mithran https://www.tecmint.com/use-linux-awk-command-to-filter-text-string-in-files/comment-page-1/#comment-1058324 Mon, 12 Nov 2018 10:04:23 +0000 http://www.tecmint.com/?p=19807#comment-1058324 In reply to Erick Manuel Bazán.

HI,

Can you please provide the script details further, if possible

Thanks & Regards,
Mithran

]]>