LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   awk from end of string -3 position comparison (https://www.linuxquestions.org/questions/linux-software-2/awk-from-end-of-string-3-position-comparison-835978/)

dazdaz 10-03-2010 04:40 PM

awk from end of string -3 position comparison
 
Hi, I would like to check if the 3rd character from the end of a string is a d or p using awk and the field seperator would not help for this problem, i.e.

Code:

zgcdedgh
zgcdepgh
zgcdeigh

Any tips would be appreciated.

hackerb9 10-03-2010 08:31 PM

Why not use a regular expression like /d..$/ or /p..$/ ?

--b9

ghostdog74 10-03-2010 11:55 PM

Code:

# awk -vFS= '$(NF-2) ~ /[dp]/' file
zgcdedgh
zgcdepgh


kurumi 10-04-2010 12:33 AM

Code:

$ ruby -ne 'print if $_.chomp[-3][/[dp]/]' myfile

dazdaz 10-04-2010 10:31 AM

Tanks
Tanks
Tanks


All times are GMT -5. The time now is 08:23 AM.