LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Quick AWK question... (https://www.linuxquestions.org/questions/linux-newbie-8/quick-awk-question-586428/)

WingnutOne 09-21-2007 05:03 PM

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!

bigrigdriver 09-21-2007 06:03 PM

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.

David the H. 09-21-2007 07:02 PM

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. :twocents:

bigrigdriver 09-21-2007 07:38 PM

Thanks. I learned something new today.

colucix 09-22-2007 05:33 AM

Quote:

Originally Posted by bigrigdriver (Post 2899661)
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! :eek:

druuna 09-22-2007 05:56 AM

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.

WingnutOne 09-24-2007 08:15 AM

Quote:

Originally Posted by druuna (Post 2900016)
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!

druuna 09-24-2007 08:42 AM

Hi,

You're welcome :)


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