ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
I have a text file that's in the following format:
------------------------------------------------
Company Name Date Type Num Due Date Amount Open Balance Balance
"Abernathy Drive, 4473"
James and Barbara -240.00 -240.00 0.00
"Total for Abernathy Drive, 4473"
"Abernathy Drive, 4481"
Jane 01/01/2003 Invoice 3297 01/01/2003\
------------------------------------------------
I only want the text between the " marks.
So my result could be:
"Abernathy Drive, 4473"
"Total for Abernathy Drive, 4473"
"Abernathy Drive, 4481"
or that without the " marks.
Any help with a script would be great. You guys have always been great in the past, and I thank you in advance for any assistance.
I tried something similar to that, but it doesn't work, because the data is not split into separate lines, so I still get all the data returnded. Sorry, I should have been clearer
Ok,like I mentioned the text is not split on separate lines like I originally posted, it looks more like this:
Company Name Date Type Num Due Date Amount Open Balance Balance
"Abernathy Drive, 4473" James and Barbara -240.00 -240.00 0.00 "Total for Abernathy Drive, 4473" "Abernathy Drive, 4481"
Grep searches and returns the line. which includes all the other data too, unfortunately.
Basically, an awk program consists of one or more of these: <pattern>{<what to do when this pattern is seen>}.
That sounds quite simple, and it is, but it is also remarkably powerful and there are many good examples provided.
The two main "interesting" features of this file are that the first line is treated separately and that the data includes quoted strings. Both of these can be handled quite directly in awk.
Awk is a very useful tool for jobs that are more complex than what grep can do. The "regular expression" capabilities of both are the same. Awk includes a fully-featured programming language based loosely upon "C."
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.