Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting c++ values from awk output

Tags:

c++

awk

system("awk 'BEGIN {i=0;}$0 ~/^D/ { i++; printf "i";}END {}' out.txt"); 

I have used this line in my c++ code to count some lines in out.txt. it printing correct i value. now i need to use this i count value in c++. can any one help me to do this.

like image 883
Naveen.S Avatar asked Sep 10 '26 07:09

Naveen.S


1 Answers

You need to use popen, instead of system.

see here: http://pubs.opengroup.org/onlinepubs/009696799/functions/popen.html

It's like a cross between fopen() and system(), it "returns" the output of the system call as a unix-style pipe, which is much like a FILE*.

like image 69
RichardPlunkett Avatar answered Sep 11 '26 20:09

RichardPlunkett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!