LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 05: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, 06:03 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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 07:37 PM.
 
Old 09-21-2007, 07:02 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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, 07:38 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

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

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
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, 05:56 AM   #6
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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, 08: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, 08:42 AM   #8
anon237
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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 07:51 AM
awk question davidkline Linux - General 9 09-29-2006 12:37 PM
question about awk perfect_circle Programming 4 07-19-2006 02:34 PM
Awk question blanny Linux - Software 6 05-02-2006 08:03 AM
awk question puishor Programming 2 08-26-2005 09:44 AM

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

All times are GMT -5. The time now is 06:30 AM.

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
Open Source Consulting | Domain Registration