gerp 1 查詢檔案中指定的字串,並列印該行

2021-06-08 02:58:18 字數 659 閱讀 9848

/** @autho: yj   

* @function: like gerp command in linux: find lines with a specified string in a file, and print these lines.

* @usage: ./grep [string] [filename]

**/#include#include#include#define max 100

int strindex(char s, char t);

int main(int argc, char *argv)

if((fp = fopen(argv[2], "r")) == null)

/*read one line from a file*/

while(!feof(fp))

}printf("total lines: %d\n", found);

return found;

}/*find position of string t, and return position; if not exist, return -1 */

int strindex(char s, char t)

return -1;

}

使用vi查詢檔案中指定內容並輸出到檔案

今天碰到這樣乙個需求,大概有100多個檔案,需要從這些檔案裡面找到一些具有相同格式的 然後把他們統一輸入到乙個txt中去。拿到需求後,我的第乙個想法就是使用vi,於是就嘗試了一下,得到了乙個不是很好的解決方案,如下 set nows map 1 gg write c temp.txt 2 map 2...

python查詢字串中指定字元的索引

當你想查詢乙個字串中指定字元的位置時,很容易就想到用index方法,但如果字串有多個該字元,你會發現只能查到第一次出現的位置,而python是沒有內建方法去解決這個問題的,所以需要自己去定義乙個方法去查詢。def indexmany s,str str是要查詢的字元 length len s 獲取該...

python實現查詢檔案名包含指定字串的檔案

1 當前目錄以及當前目錄的所有子目錄下查詢檔案名包含指定字串的檔案,並列印出相對路徑。自廖雪 峰的官方 實現如下 import os def myfind pattern,root for each in os.path.listdir root if os.path.isdir os.path.j...