The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
iCal, Mac OS X 10.5: Empty "Home" and "Work" calendars may appear after installing Le iBot OS X Support RSS 0 10-13-2008 10:20 PM
iCal, Mac OS X 10.5: Empty "Home" and "Work" calendars may appear after installing Le iBot OS X Support RSS 0 10-03-2008 04:40 AM
acessing awk array element while getline < "file" timj123 Shell Programming and Scripting 9 06-27-2008 11:13 PM
awk: getline NOM < "-" script does not stop Klashxx Shell Programming and Scripting 2 05-17-2006 02:20 AM
By angle-brackets/"pipe" button doesn't work? riwa Linux 1 04-02-2006 06:43 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-07-2009
qiulang qiulang is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 34
awk's getline < "-" seems not work for pipe

Hi all,

I have an gawk script to get user's input, So I use

getline name < "-" (or getline name < "/dev/stdin") in my script

They both work fine when my script deals with files. But it is broken for pipes.
When I try "some command | my awk script", the variable name just gets an empty value (""), it does not get the value from stdin at all.

Why is that ? And how do I fix it ?

Last edited by qiulang; 04-08-2009 at 08:01 AM..
  #2 (permalink)  
Old 04-08-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,391
as far as i know get line deals with following six varients
Code:
getline 
sets $0, NF, FNR, and NR. 
getline var 
sets var, FNR, and NR. 
getline < file 
sets $0, and NF. 
getline var < file 
sets var. 
command | getline 
sets $0, and NF. 
command | getline var 
sets var.
no where its mentioned that it take i/p from stdin
  #3 (permalink)  
Old 04-08-2009
qiulang qiulang is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 34
It mentions in gawk user's guide The GNU Awk User's Guide
(seach "-").

And it works for files processing. Just seems not work for pipe.
  #4 (permalink)  
Old 04-08-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,391
Quote:
Originally Posted by qiulang View Post
It mentions in gawk user's guide The GNU Awk User's Guide
(seach "-").

And it works for files processing. Just seems not work for pipe.
Buddy that means
if getline < "filename"
some command ' file2
now it getline read from filename
if getline < "-"
some command' file2
now it read from file2
it doesn't mean that it read from stdin
  #5 (permalink)  
Old 04-08-2009
qiulang qiulang is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 34
Quote:
Originally Posted by vidyadhar85 View Post
Buddy that means
if getline < "filename"
some command ' file2
now it getline read from filename
if getline < "-"
some command' file2
now it read from file2
it doesn't mean that it read from stdin
Hey just take a try getline name < "-" you will know it will work for file processing.

Actually "sed & awk" had several examples of getline < "-" to read user's input from stdin.

I just want to know how to make it work for pipe.
  #6 (permalink)  
Old 04-08-2009
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,866
Did you try:

Code:
command | getline
See vidyadhar85's post above.
  #7 (permalink)  
Old 04-08-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,307
Quote:
Originally Posted by qiulang View Post
Hey just take a try getline name < "-" you will know it will work for file processing.

Actually "sed & awk" had several examples of getline < "-" to read user's input from stdin.

I just want to know how to make it work for pipe.
You're right, getline < "-" gets the input from standard input.
What you can't do is to get input from a pipe and a file simultaneously. Get the users input in the BEGIN{} part.

Regards
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:31 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0