LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 10-03-2010, 04:40 PM   #1
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL 6.x, 5.x, Fedora 20, Kubuntu 12.04, Solaris 10,8
Posts: 321

Rep: Reputation: 17
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.
 
Old 10-03-2010, 08:31 PM   #2
hackerb9
LQ Newbie
 
Registered: Oct 2010
Distribution: Gnewsense
Posts: 2

Rep: Reputation: 0
Lightbulb

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

--b9
 
Old 10-03-2010, 11:55 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 239Reputation: 239Reputation: 239
Code:
# awk -vFS= '$(NF-2) ~ /[dp]/' file
zgcdedgh
zgcdepgh
 
Old 10-04-2010, 12:33 AM   #4
kurumi
Member
 
Registered: Apr 2010
Posts: 223

Rep: Reputation: 45
Code:
$ ruby -ne 'print if $_.chomp[-3][/[dp]/]' myfile

Last edited by kurumi; 10-04-2010 at 12:34 AM.
 
Old 10-04-2010, 10:31 AM   #5
dazdaz
Member
 
Registered: Aug 2003
Location: Europe
Distribution: RHEL 6.x, 5.x, Fedora 20, Kubuntu 12.04, Solaris 10,8
Posts: 321

Original Poster
Rep: Reputation: 17
Tanks
Tanks
Tanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Awk: match string in exact position sebelk Programming 2 10-19-2009 02:15 PM
Using sed/awk to replace a string at a given position in anoopvraj Linux - Newbie 6 05-30-2009 07:59 AM
string comparison in bash davimint Programming 4 01-23-2008 06:36 PM
String Comparison gjagadish Programming 6 11-06-2007 03:34 AM
bash string comparison noir911 Programming 1 01-25-2006 06:37 PM


All times are GMT -5. The time now is 07:46 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration