查詢指定檔案中特定字串賦值

2021-06-11 16:28:21 字數 1008 閱讀 9511

#include

#include

#include

#include

#include

#include

#include

#include

static unsigned long get_file_size(const char *path)

return -1;

}static unsigned int print_network_name(void)

fd = open("./sets.conf", o_rdonly);

if(-1 == fd)

size = read(fd, buffer, filesize);

if(size != filesize)

close(fd);

p = strstr(buffer, "networkdevice");

memcpy(tmpbuf, p, (unsigned int)((p - buffer)/sizeof(char)));

p = strstr(tmpbuf, "devicename");

p += sizeof("devicename");

while(*p != '\n')

buf[i] = '\0';

free(buffer);

free(tmpbuf);

memset(strbuf, 0xff, 100);

sprintf(strbuf, "networkname : %s", buf);

printf("%s \n", strbuf);

return 0;

}void main(void)

print_network_name(();

查詢sets.conf中[networkdevice]欄位下 devicename的賦值。

[networkdevice]

connectednetwork=dhcp

devicename=eth0

Linux 查詢檔案中的特定字串

find 與 grep組合查詢 find name 檔案型別 xargs grep n 查詢內容 檔案型別可正規表示式通配,表示當前目錄下進行查詢,也可自由指定目錄.比如 find etc name properties xargs grep n cachesize 查詢 etc目錄下,包含cach...

vim中查詢指定字串

0x01 自當前游標位置向上搜尋 pattern enter pattern表示要搜尋的字串 0x02 自當前游標位置向下搜尋 pattern enter 0x03 n繼續從同一方向搜尋 n反方向搜尋 0x04 要查詢單個的pattern,在這個字串前後都加乙個空格 pattern enter 0x...

Linux查詢含有特定字串的檔案

linux查詢含有特定字串的檔案命令為grep。以下為詳細的使用方法 grep options pattern file.例項 遞迴查詢當前資料夾下所有含有test的檔案,並顯示行號 grep rn test r 遞迴查詢 n 顯示行號 i 忽略大小寫 w 只匹配整個單詞,而不是字串的字部分 如pa...