我有2個單獨的文件lostType.txt(顯示選定的選項)和lost.txt(顯示內存泄漏)我使用dialog來創建GUI。使用複選框,我正在從用戶處獲取一些數字間隔來限制將要打印的內存泄漏。我要做的就是,打印的內存泄漏是在選定的尺寸的線,和泄漏類型是lostType.txt如何在awk中搜索文件
例如,這是lost.txt
LEAK SUMMARY
100 bytes definitely lost
0 bytes indirectly lost
0 bytes possibly lost
100 bytes still reachable
0 bytes suppressed
如果用戶想要查看definetely丟失和間接丟失,lostType.txt
具有選擇爲看到泄漏,其中大小爲0和10個字節或100個和250個字節之間的以下
definetely
indirectly
假設用戶。現在,輸出必須是100 bytes in 1 blocks definitely lost
我做了什麼至今如下,
for choice in $choices
do
case $choice in
1)
#"Memory Leak <= 10 Byte"
cat lost.txt | awk '{
if ($1 <= 10 && $1 > 0)
print $1,$2" ==>",$3,$4
}'
;;
2)
#"10 Byte < Memory Leak <= 50 Byte"
cat lost.txt | awk '{
if ($1 <= 50 && $1 > 10)
print $1,$2" ==>",$3,$4
}'
;;
也就是說,根據所選擇的大小間隔,我可以打印值。但是,我找不到找到lostType的方法(上面的代碼爲$ 3)。我需要做的是尋找像
cat lost.txt | awk '{
if ($1 <= 50 && $1 > 10 AND IF $3 IS IN lostType.txt)
print $1,$2" ==>",$3,$4
}'
;;
所以我的問題是在awk中的文件,我怎麼可以搜索裏面AWK文件?
PLS。避免使用'cat file | awk ...'。改用'awk ... file'。 – TrueY