[英]Read a file line by line -> search for each line in another text document, if match, output to another text file
[英]how to read a file line by line and each line as an argument input to a .exe file and capture the output to another file in linux
我嘗試編寫一個 shell 腳本逐行讀取 a.txt 文件,每一行都將作為 my.exe 文件的輸入,我還想捕獲.exe 文件的 output 並將其導出到另一個.txt 文件. 我的代碼喜歡這樣,但它不起作用。 當我嘗試像“./caculate.exe“1”這樣手動輸入時,程序也不將1作為輸入,仍然要求我再次手動輸入。
#!/bin/bash
while IFS= read -r LINE; do
./caculate.exe "$LINE"
done < data.txt > f.txt
如果calculate.exe
通常從標准輸入中獲取輸入,則需要將變量pipe給它,而不是使用參數。
#!/bin/bash
while IFS= read -r LINE
do
printf "%s\n" "$line" | ./calculate.exe
done < data.txt > f.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.