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! |
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. |
Quote:
|
Thanks. I learned something new today.
|
Quote:
|
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. |
Quote:
The line you came up with Code:
awk '!/[\.!?"]$/ { print }' infile Thank you all! |
Hi,
You're welcome :) |
All times are GMT -5. The time now is 11:11 PM. |