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.
currently this script is supposed to ask what the cquestions is like "what is your name?" then next it should print all the dn values from the a.txt file which is a big file and sections of it like:
I really appreciate for the help. I am still trying to figure out why I couldnt make it run. When I run this: awk -f gtest.awk a.txt I get an error ,...perhaps something I did wrong in the script...please have a look if you get a min...I would really appreciate...
I really appreciate for the help. I am still trying to figure out why I couldnt make it run. When I run this: awk -f gtest.awk a.txt I get an error ,...perhaps something I did wrong in the script...please have a look if you get a min...I would really appreciate...
Maybe the reason is your awk interpreter? Please post the output of `awk --version' as well as your distribution (I use Debian for example and GNU awk 3.1.5). You also can omit '< "/dev/tty"' from call to getline, because it is useless IMO and your awk may not understand redirection. If that did not work you can try getline without arguments, and then assign the value of $0 to choice. And if that will not work... ok, just use BASH features:
not really.
...
if "/dev/tty" is not used, the first $0 is "gobbled" up.
@OP, if your system has nawk, you can try that and see.
Yes, you right, ghostdog74, sorry.
cmontr, please post some info about your environment, at least version of your awk interpreter. On my system all mentioned scripts work well without error messages and some of them do exactly what you want.
If the reason is in `getline' statement or not, this can be checked simply by using `choice="..."' instead of `getline'.
in my system awk --version doent bring anything ...it is SUN ultra 250 running solaris 5.7 and oracle 9i db. Please let me know what commands you like m to run for a specific information.
On this site I found that your version of awk uses very restricted syntax of `getline' statement:
Code:
getline
Set $0 to the next input record from the current input file. getline returns 1 for successful input, 0 for end of file, and -1 for an error.
.. and there is nothing about redirection (I mean this `<"/dev/tty"').
But there is another man page describing `nawk' (man nawk) which is placed in /usr/bin/nawk or /usr/xpg4/bin/awk. nawk seems to possess all the features we need, so try it.
Anyway you can just pass the variable `choice' to the interpreter:
Code:
$ nawk -v 'choice=...' -f ctest.awk a.txt
and use a shell script to obtain actual value for `choice'.
P.S.: If "/dev/tty" do not work for you, try "/dev/stdin", it should be there I think.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.