awk system() prints extra 0 -- why?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk system() prints extra 0 -- why?
# 1  
Old 03-12-2010
awk system() prints extra 0 -- why?

Here's the command I'm running:

Code:
# echo "hi" | awk '{etime = system("hostname") ; close("hostname") ; print etime""}'

And here's the ouput:

Code:
server.domain.tld
0

Why in the world is that second line, the one that's just "0", there? Many thanks in advance.
# 2  
Old 03-12-2010
'man nawk' yields:
Code:
     system(expression)
           Execute the command given by expression  in  a  manner
           equivalent  to  the system(3C) function and return the
           exit status of the command.

Your '0' is the exit code of the exec-ed 'command'.
Code:
echo "hi" | awk '{cmd="hostname"; cmd | getline etime; close(cmd) ; print etime}'

# 3  
Old 03-12-2010
Ah, thanks for the reply. Somehow I missed that. The awk (not [m/n/g/h]awk) man page makes a similar statement that I somehow managed to completely overlook. Thanks for the clever solution as well. Well, clever to me, anyway... I'm sure it's second nature to you folks that actually know this stuff...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: BEGIN: prints nothing

My code fails to do anything if I've BEGIN block in it: Run the awk script as: awk -f ~/bin/sum_dupli_gene.awk make_gene_probe.txt #!/usr/bin/awk -f BEGIN { print ARGV #--loads of stuff } END{ #more stuff } (14 Replies)
Discussion started by: genome
14 Replies

2. Shell Programming and Scripting

awk prints only last line

data.txt: NEWTEXTS="frq=63,std=-0.00533584,time=Mar-21-(09:15:03)-2016,epoch=1458576903,avg=64.2059,212.698 frq=197,std=0.587585,time=Mar-21-(09:16:02)-2016,epoch=1458576962,avg=64.2059,483.756 frq=178,std=0.503514,time=Mar-21-(09:46:02)-2016,epoch=1458578762,avg=64.2059,500... (5 Replies)
Discussion started by: SkySmart
5 Replies

3. Shell Programming and Scripting

awk - Removing extra character when setting variable

I have a data file d0 that looks like this: $cat d0 server1 running -n-cv- 8G 3.1% 1435d 15h server2 running -n---- 8G 39% 660d 22h server3 running -n--v- 8G 2.5% 1173d 6h server4 running -n---- 8G 1.1% 1048d 20h... (2 Replies)
Discussion started by: jake0391S
2 Replies

4. Shell Programming and Scripting

awk prints unwanted new lines

Hello, I need a little help with the following: I'm using AWK to read input from a comma-seperated value file, and only printing certain fields like so: awk -F "," '{print $1,$3,$6}' /list.csv | tail -1 Which outputs the following: server1 APPID OS I run into a problem... (8 Replies)
Discussion started by: LinuxRacr
8 Replies

5. SCO

How to add extra memory to root file system in UNIXware7.1.3?

Sir I have installed unixware7.1.3 on vmware workstation previously and I have allotted 8GB to the whole system. I want to add extra space to the existing system by using another virtual harddisk added by using VMware. Kindly suggest the procedure. Regards, Rupesh. (3 Replies)
Discussion started by: rupeshforu3
3 Replies

6. UNIX for Dummies Questions & Answers

awk for removing special characters and extra commas

Hi, I have a .csv file which as empty lines with comma and some special characters in 3rd column as below. Source data 1,2,3,4,%#,6 ,,,,,, 1,2,3,4,5,6 Target Data 1,2,3,4,5,6I need to remove blank lines and special charcters I am trying to get this using the below awk awk -F","... (2 Replies)
Discussion started by: shruthidwh
2 Replies

7. Shell Programming and Scripting

Awk while-loop printing extra character

Hi, I'm using a while-loop in an awk script. If it matches a regular expression, it prints a line. Unfortunately, each line that is printed in this loop is followed by an extra character, "1". While-statement extracted from my script: getline temp; while (temp ~ /.* x .*/) print temp... (3 Replies)
Discussion started by: redbluefish
3 Replies

8. Shell Programming and Scripting

extra space issue with awk

for diskname in $(lspv |awk '{print $1}') do lquerypv -h /dev/|awk '/'$diskname'/ { print ; exit }' done No output is returning from the loop. I think awk put an extra space to the command - lquerypv -h /dev/ so that the command is executed as i.e. lquerypv -h /dev/ hdisk230 with a space... (7 Replies)
Discussion started by: Daniel Gate
7 Replies

9. Shell Programming and Scripting

awk / grep / Prints all columns except the first one

I have the a file with the following data. File Content. 1249 snf06.3.0 sw version 1.1 code MD5 192F MD4 MD3 1248 sns06.3.0 sw version 1.1 code MD5 192F MD12 1250 sns06.3.0 sw version 1.1 code MD5 192F0\ MD8 1241 sns06.3.0 sw code MD5 19 1243 sn06.3.0 sw version 1.1 code MD5 19 12... (17 Replies)
Discussion started by: knijjar
17 Replies

10. UNIX for Dummies Questions & Answers

Prints Problems on Unix system

We are experiencing printing problems coming from an Unix host. In Feb. 05 we applied patches to the Unix operating system. Shortly the patches were applied we began experiencing problems printing on a IBM 6400 that emulates an Epson printer. When the printing starts we can print about 10 pages and... (1 Reply)
Discussion started by: ddameron
1 Replies
Login or Register to Ask a Question