linux - Scanning the output of a program at shell -


hello trying make script file in linux has input output of o prgram , scans find how many occurences of words existed. clearer want scan output , store variables how many times words exist in output. new scripitin in linux. tried storing output in file , scan line line in order find words somre reason loop use parse never ends. can me?

./program > buffer.txt  while read line echo $line | grep word1  #when use grep command loop never ends done <a.txt 

edit: in c equivalent program be

char* word="word1" while(/*parse lines @ text */) { fgetline("file_a",&buffer) if(strcmp(buffer,word)==0)  strcpy(word1,"word") //continue search  } 

the easiest thing skip writing file altogether

if ./program | grep -q word1 &>/dev/null;     echo "true" fi 

-q tells grep quiet, can still produce error messages can suppress w/the &>/dev/null. if you'd prefer see error messages, remove part. if want ./program's errors , stdout analyzed grep you'll need redirect stderr stdout this


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -