LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-21-2007, 06:03 PM   #1
WingnutOne
Member
 
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Rep: Reputation: 16
Question Quick AWK question...


Within awk, how do you tell it to perform (action_X) on any line where the last character is NOT one of the characters . or ? or ! or " (dot, question mark, ballbat, or double quote)?

I don't know the syntax rules very well yet and I'm pulling my hair out trying to figure out how to get it to do all of those things at once!

Thanks!
 
Old 09-21-2007, 07:03 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,896

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
There are two awk users guides you can download which might help: Effective AWK Programming and The GNU AWK Users Guide.

In the first, see chapter 4.3 on the use of anchors and character classes.
The character class and anchor given as [:\punct:]$ would apply to punctuation characters (not alphanumeric and not control character) at the end of the line. Negating that class means adding the ! before the class: ![:\punct:]$. Note that the backslashes are not in the class. I had to include those to keep the colon p from being interpred as a smiley face :p.

Beyond that I can't help. I don't use awk enough to be able to tell you the whole command line to use. You should be able to work it out fron the two documents named above.

Last edited by bigrigdriver; 09-21-2007 at 08:37 PM.
 
Old 09-21-2007, 08:02 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Note that the backslashes are not in the class. I had to include those to keep the colon p from being interpred as a smiley face .
No you didn't. Just go into advanced edit mode and check the "disable smilies in text" box. Problem solved.
 
Old 09-21-2007, 08:38 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,896

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Thanks. I learned something new today.
 
Old 09-22-2007, 06:33 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Quote:
Originally Posted by bigrigdriver View Post
There are two awk users guides you can download which might help: Effective AWK Programming and The GNU AWK Users Guide.
Sure? I have always thought they were the same!
 
Old 09-22-2007, 06:56 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Hi,

This should do what you want:

awk '!/[\.!?"]$/ { print }' infile

All between /.../ is seen as a regular expression: [\.!?"]$ -> the four chars you want on the end of a line
The ! in front of the /../ makes it a not statement (everything but the regexp that follows).
In the above example the { print } part is a simple action.

Hope this helps.
 
Old 09-24-2007, 09:15 AM   #7
WingnutOne
Member
 
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76

Original Poster
Rep: Reputation: 16
Thumbs up

Quote:
Originally Posted by druuna View Post
Hi,

This should do what you want:

awk '!/[\.!?"]$/ { print }' infile

All between /.../ is seen as a regular expression: [\.!?"]$ -> the four chars you want on the end of a line
The ! in front of the /../ makes it a not statement (everything but the regexp that follows).
In the above example the { print } part is a simple action.

Hope this helps.

The line you came up with
Code:
 awk '!/[\.!?"]$/ { print }' infile
is a lot simpler than what I was trying to do! (I haven't gotten into regular expressions at all yet.)


Thank you all!
 
Old 09-24-2007, 09:42 AM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Hi,

You're welcome
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
quick hand with awk multiple field separators pld Programming 10 05-28-2010 08:51 AM
awk question davidkline Linux - General 9 09-29-2006 01:37 PM
question about awk perfect_circle Programming 4 07-19-2006 03:34 PM
Awk question blanny Linux - Software 6 05-02-2006 09:03 AM
awk question puishor Programming 2 08-26-2005 10:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:43 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration