Results 1 to 2 of 2
I have a problem with awk..
Is it possible to create a script in AWK that reads that input of a user from a keyboard..
Something like:
Prompts the user ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-05-2006 #1Just Joined!
- Join Date
- Jun 2006
- Posts
- 15
AWK scripts..
I have a problem with awk..
Is it possible to create a script in AWK that reads that input of a user from a keyboard..
Something like:
Prompts the user for some string input and stores this string into a variable which will be use in the process.. ? ..
- 09-05-2006 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,199
Hi, ethnicme.
Yes it is possible, although it may not be obvious. One way is illustrated here:
When this is run with an existing trivial file:Code:#!/usr/bin/awk -f #!/usr/bin/nawk -f #!/usr/bin/mawk -f #!/usr/bin/gawk -f # @(#) a4 Demonstrate awk writing to, reading from terminal. # Note that the "-f" is required in the sh-bang line. # Use: ./a4 file -or- ./a4 /dev/null # Verified with awk, nawk, gawk, mawk. BEGIN { print "System " ARGV[0] ": enter your name" > "/dev/tty" getline name < "/dev/tty" } { print $0 } END { print "I read your name as: " name > "/dev/tty" }
Best wishes ... cheers, drlCode:% ./a4 data1 System awk: enter your name drl Hello, world. I read your name as: drl
PS Questions like this will probably get more exposure in the Linux Programming & Scripting forum.
( edit 1: add PS )Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote
