LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-27-2007, 05:31 AM   #1
khaan
LQ Newbie
 
Registered: Feb 2007
Distribution: ubuntu
Posts: 24

Rep: Reputation: 15
How to make extra stdin input in awk ?


Hi,

I am quite new at using awk and did not managed to get the following thing working:

I want to read and process some data (with some output redirection), and under given circumstances ask the user a question "and what to do with that ?", wait for an answer, do the appropriate action and resume the processing.

I found a sample program on the internet for reading standard input, but it generates a syntax error for me (line 2):

Code:
BEGIN { printf "Enter your name: "
	getline < "-"
	print  
}
Any help would be appreciated!
 
Old 07-27-2007, 09:29 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Which version of gawk do you have on your system? You can try to put parentheses at line 2, as in:
Code:
BEGIN { printf "Enter your name: "
	getline < ("-")
	print  
}
an explanation of this is in the "GAWK: Effective AWK Programming" guide (a must read for awk programmers) page 50.
 
Old 07-30-2007, 02:23 AM   #3
khaan
LQ Newbie
 
Registered: Feb 2007
Distribution: ubuntu
Posts: 24

Original Poster
Rep: Reputation: 15
Well, I first wanted to make my code run on the university server. It does not have gawk. It is a solaris with an old awk I could not version. I just have the last change of its man page going back to 2000.

Anyway, thank you for your help, I'll try the snipet at home as soon as I can.
 
Old 07-30-2007, 05:04 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Ok. However, take in mind that on most Solaris an extended version of awk called nawk is installed by default. I don't know exactly what are the differences and the portability issues between nawk and gawk, but on Solaris itself you have another chance. Good luck!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Awk to make Archives based on dates. HunterColt22 Linux - Newbie 4 05-29-2007 02:50 AM
How add input value to some varieble in awk program this is probably funny for some of you but I do not know what to do. I have sarajevo Programming 2 05-25-2007 07:54 AM
Adding extra input on reboot option D3javu Linux - General 2 08-04-2006 06:48 AM
httpd-2.0.52 configure before make with 2 extra modules tca23 Linux - Software 3 11-19-2004 10:51 PM
How can I make this extra partition user-accessable? enigma Z Linux - Hardware 2 09-05-2004 10:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration