A twisted feature of sort when called in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A twisted feature of sort when called in awk
# 8  
Old 12-04-2009
Quote:
Originally Posted by nrgbooster
Then I must have failed to understand the underlying mechanism of pipe. I had always thought that the command in a pipe will never do its job until the preceding one completes and hands over the output.
Consider the following:

Code:
% for i ({1..3}) { print $i; sleep 3;} | perl -nle'print "got: ", $_, " at: ", ~~localtime'
got: 1 at: Fri Dec  4 16:21:56 2009
got: 2 at: Fri Dec  4 16:21:59 2009
got: 3 at: Fri Dec  4 16:22:02 2009

The short form of the for loop is a Z Shell syntactic sugar Smilie
# 9  
Old 12-04-2009
Simple proof that all commands start running right away, not when the previous completed:
Code:
for i in 1 2 3 4 5; do sleep 2; echo $i; done | awk 'BEGIN { print "START" } { print; }'

# 10  
Old 12-04-2009
Quote:
Originally Posted by pludi
Simple proof that all commands start running right away, not when the previous completed[...]
Or Smilie

Code:
% { echo echo 1;sleep 1;echo echo 2;}>/dev/tty|awk 'BEGIN{print ARGV[0],"ready ..."}x'
echo 1
awk ready ...
echo 2

# 11  
Old 12-05-2009
pludi, radoulov:

Great examples; totally hit the essence.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk call in bash function called with arugments not working, something lost in translation?

Hello, I have this awk code in a bash script to perform a find and replace task. This finds one unique line in a file and substitutes the found line with a replacement. #! /bin/bash # value determined elsewhere total_outputs_p1=100 # file being modified... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

2. Shell Programming and Scripting

Sort String using awk

Hi, I need help to sort string using awk. I don't want to use sed or perl as I want to add this functionality in my existing awk script Basically I have a variable in AWK which is string with comma separated value. I want to sort that string before using that variable in further processing for... (10 Replies)
Discussion started by: rocky.community
10 Replies

3. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

AWK new line feature getting nullified in outlook

Hi, I am using the below code to send mail to users showing the details of errors, and this happens in a loop till all the lines are validated. printf... (2 Replies)
Discussion started by: ramkiran77
2 Replies

5. Shell Programming and Scripting

awk sort

input file abc1 abc23 abc12 abc15 output abc1 abc12 abc15 abc23 (9 Replies)
Discussion started by: yanglei_fage
9 Replies

6. Shell Programming and Scripting

Sort in AWK

Hi, I usually use Access to sort data however for some reason its not working. Our systems guys and myself cannot figure it out so ive tried to use AWK to do the sorting. The file is made up of single lines in the format ... (4 Replies)
Discussion started by: eknryan
4 Replies

7. Homework & Coursework Questions

awk sort help

1. The problem statement, all variables and given/known data: I dont know what I do wrong, I am trying to create shell programming database: I have this command first: && > $fname ... echo $Name:$Surname:$Agency:$Tel:$Ref: >> $fname then I have echo " Name Surname Agency Tel... (2 Replies)
Discussion started by: jeht
2 Replies
Login or Register to Ask a Question