problem while comparing awk field variable with input variable entered using keyboard
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.
Please use [code][/code] tags around your code, to preserve formatting and to improve readability.
Shell variables are NOT awk variables! They may look the same at first glance, but awk uses a separate variable system with a slightly different syntax.
You have to import the bash variable into an awk variable before you can use it. (It's also possible by using careful quoting of the awk expression to allow shell expansion, but it's usually better to import it.
Notice first that the values of awk variables are read with the name only. Adding "$" to it references the field of the input text, if the variable contains a number.
Also, you can usually do everything you want in a single awk instance. It's a full scripting language of its own, after all: http://www.grymoire.com/Unix/Awk.html
(BTW, why are you testing the same field for both day and month?)
Finally, however, parsing ls isn't recommended. Perhaps if you explain what your real goal is, we could help you develop a better way to do what you want.
Last edited by David the H.; 08-16-2011 at 12:02 PM.
hi david , my goal is based on the key board input i have to get the list of files of specific pattern and date and copy the same to say /files/jjj/ab directory
It always good to point out when you're using Unix-based applications. Since this is a Linux forum we tend to assume gnu utilities by default. I suppose you aren't using bash either, then?
Could you please post some specific examples of the directory structures, names, and dates that you want to locate?
It seems to me that you'd be better off with a simple find command instead. Just plug the variable into the find regex to get the matches you want. Something like this, perhaps?
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by vinay007
my script is on solaris and i am getting
awk:syntax error near line 1
awk:bailing out error near line 1
can you please suggest the same above code in SOLARIS
Just a comment about awk and Solaris.
On Solaris 10 and older, /usr/bin/awk is a legacy binary that doesn't comply with standard awk. It is there only to maintain compatibility with old scripts that might still stay around.
For new scripts, you should always use /usr/bin/nawk (for new awk) instead. nawk is faster and complies with POSIX awk. For pure standard compliance, you might also use /usr/xpg4/bin/awk. If you are using Gnu specific extensions, you should instead run something like /usr/sfw/bin/gawk, /usr/local/bin/gawk, /opt/csw/bin/gawk, /usr/gnu/awk, or somewhere else depending on the Solaris release and optional packages possibly installed.
i want to search pattern along with that the file name pattern i am searching should belong to specific date i.e for example Aug 15 it should copy only august 15th files not other month 15 th files
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.