File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes use of variables in awk to search for pattern from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "use of variables in awk to search for pattern from a file" Watch "use of variables in awk to search for pattern from a file" New topic
Author

use of variables in awk to search for pattern from a file

Jean John
Greenhorn

Joined: Dec 21, 2010
Posts: 22

Hi,

I need to extract all the content between two strings stored in two variables "startstring" and "endstring"



The above code is not working with variables. It works when actual string values are used as pattern.



Can someone help me to use these two variables in awk.

Thanks.

Regards,
Jean
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12513

Unix shells have several different "quote" characters, and each one has a special meaning. For example, the backtick "quotes" cause the quoted expression to be run as a shell command.

Unfortunately, the single-quote "quotes" mean "don't expand shell variables". Use the double-quote "quotes" instead. Or, in other words:


It's a convention that environment variables should be named all in uppercase, BTW. However, that's just a convention, so using lower-case names won't actually hurt anything.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
 
 
subject: use of variables in awk to search for pattern from a file
 
Threads others viewed
can variables be used as pattern for awk command?
EJB findall method does not find persisted objects
Column number of a search pattern
Expression to get Tomcat pid?
Search on a string
developer file tools