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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-21-2007, 05:03 PM
|
#1
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Rep:
|
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!
|
|
|
09-21-2007, 06:03 PM
|
#2
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
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.
|
|
|
09-21-2007, 07:02 PM
|
#3
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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. 
|
|
|
09-21-2007, 07:38 PM
|
#4
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
Thanks. I learned something new today.
|
|
|
09-22-2007, 05:33 AM
|
#5
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Quote:
Originally Posted by bigrigdriver
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! 
|
|
|
09-22-2007, 05:56 AM
|
#6
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
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.
|
|
|
09-24-2007, 08:15 AM
|
#7
|
Member
Registered: Sep 2007
Location: Kansas City
Distribution: Mixed, mostly RH / Fedora
Posts: 76
Original Poster
Rep:
|
Quote:
Originally Posted by druuna
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!
|
|
|
09-24-2007, 08:42 AM
|
#8
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
You're welcome 
|
|
|
All times are GMT -5. The time now is 06:30 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|