utility of getline here?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers utility of getline here?
# 1  
Old 11-12-2006
echome

hi , I got a script that I don't understand.

Code:
awk '{
command="echo "$1
command | getline echome
close(command)
print $0 "\t" echome
}' < user.list

It reads the file user.list
user.list
Code:
London	John
Bridge	Peter

and sends the stream to the awk command.

I don't understand what is echome and I can't find what it is on Internet. Smilie

Thanks to help me.
# 2  
Old 11-12-2006
utility of getline here?

Hi everybody , I got a file user.list
user.list
Code:
London	John
Bridge	Peter
Denoyelle Rémi

I got a script
Code:
awk '{
 command="echo "$1
 command | getline echome
 close(command)
 print $0 "\t" echome
 }' < user.list

It just displays all the content of the record (print $0) , followed by the first field (echo $1).

Why we don't use
Code:
awk '{
 print $0,$1
 }' < user.list

. Is it exactly the same?

I know that command | getline echome . It reads each line and applies the command command to the variable echome.

Thanks you so much
# 3  
Old 11-12-2006
Quote:
Originally Posted by remid1985
hi , I got a script that I don't understand.

Code:
awk '{
   # build a variable "command" by concatinating the string "echo "
   # and a value of the FIRST field of the current record, e.g. "London",
   # "Bridge" etc....
   command="echo "$1

   # "execute" the command by invoking the content of the variable "command"
   # "read" (getline) the stdout of the executed command into a variable "echome"  
   command | getline echome

   # "close" the openned stream to the execution of command "command" 
   close(command)

   # print/output of the currect record/line separated with a "TAB" and the
   # the value of the variable "echome"
   print $0 "\t" echome
}' < user.list

It reads the file user.list
user.list
Code:
London	John
Bridge	Peter

and sends the stream to the awk command.

I don't understand what is echome and I can't find what it is on Internet. Smilie

Thanks to help me.
'echome' is a variable your read (getline) the output of the command ''echo $1" from.

I put the comments in your original code - hopefully it makes things clearER.
# 4  
Old 11-12-2006
Pls don't multi-post - threads merged.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

getline() and fclose()

Hi All, When I do man getline on my Linux system (in BASH), I see an example C code where a file is being read using getline() function. Now, my question is why there is no fclose() to close the open file pointer? People who don't have a Linux system, this is the code that I am referring... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

2. Shell Programming and Scripting

getline from another file

Here is I want to do: find lines in file filteredtrace.txt which is not continued as a multiply of 4 and strip them from file original_trace_framno. problem is awk used the ' symbol so pipe of getline has to use the " symbol while agument of sed has to use the " symbol, it doesn't... (8 Replies)
Discussion started by: lzq420241
8 Replies

3. Shell Programming and Scripting

nawk getline

I'm running the script below and get the output below against a file with lineA=aaa lineB=bbb lineC=ccc lineD=ddd I get output: lineC=ccc lineD=ddd I need the output to be: lineB=bbb lineC=ccc lineD=ddd cat filename | nawk '/lineA=aaa/ { getline; do { getline (3 Replies)
Discussion started by: toor13
3 Replies

4. Programming

getline()

I can not get 'getline()' to compile. I have tried. string curLine; //= compiler error char* curLine; //=compiler error char curLine; //=compiler error Every example I see uses a string as a getline(); parameter. It does not work for me on Fedora14 with gcc-c++. Thank you so much. This... (1 Reply)
Discussion started by: sepoto
1 Replies

5. UNIX for Dummies Questions & Answers

getline value to pattern

BEGIN { system("clear") blank = " " printf("Please enter your name or emp# : > ") getline < "/dev/tty" printf(">>>>> %s",$1) } /$1/ {.......... I would like for the customer to enter name or... (3 Replies)
Discussion started by: Morph797
3 Replies

6. Shell Programming and Scripting

errors while using getline

i wrote following script to test getline BEGIN{ while ( "who" | getline > 0) nr++ print nr } when i run this script as awk -f scriptname (2 Replies)
Discussion started by: asalman.qazi
2 Replies

7. Shell Programming and Scripting

How to Unzip a file using unzip utility for files zipped without zip utility ?

Hi, I need to zip/compress a data file and send to a vendor. The vendor does have only unzip utility and can accept only .ZIP files. I do not have zip utility in my server. How do I zip/compress the file so that it can be deflated using unzip command ? I tried gzip & compress commands, but... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies

8. Shell Programming and Scripting

awk getline

How do you make the getline function return to the original line? The example below should make it clear where I am currently going wrong. Thanks AWK SCRIPT: ------------- awk -F '-' '{ tmpLine = "EMPTY" print "CURRENT LINE :"$0 getline tmpLine print "NEXT LINE :"tmpLine }'... (1 Reply)
Discussion started by: garethsays
1 Replies

9. Programming

'getline' questions

I have a C program I've written that includes a 'getline' call that is used to read a line at a time from a file and process the information in each line. A potential problem comes up since I don't know the maximum length of each line; right now I'm using a constant of 256, but that might not be... (2 Replies)
Discussion started by: cleopard
2 Replies

10. Shell Programming and Scripting

getline with a unique

I have an inputfile that I trying to awk with a getline(Solaris v8 ksh). However I need to have the results be a unique. Is there a comparable command within awk to return a unique result? Or can you break out of the awk to add a uniq. I am looking for something more complex then a pipe... (6 Replies)
Discussion started by: gozer13
6 Replies
Login or Register to Ask a Question