我希望阅读特定文件夹中的所有文本文件.文件的名称中没有任何共同的模式 - 否则任务会更容易.
//read a file from the directory
//Perform a common operation
//write output to a common file
//read the next file
Run Code Online (Sandbox Code Playgroud)
如果我可以解决子文件夹也会很好,但即使是基本的实现也足够了.
我试着查看之前提到的相关问题(这里,这里,这里和这里),但没有一个给出我需要的C和Linux特定答案.
编辑:所以,这是我根据收到的答案写的 -
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char **argv)
{
DIR* FD;
struct dirent* in_file;
FILE *output_file;
FILE *entry_file;
char buffer[BUFSIZ];
/* Opening common file for writing */
output_file = fopen("/home/pnp/snort_rules_folder/rulesoutput.txt", "a+");
if (output_file …Run Code Online (Sandbox Code Playgroud) 我使用以下'grep'命令来获取alert给定路径中每个文件中字符串的计数:
grep 'alert' -F /usr/local/snort/rules/* -c
Run Code Online (Sandbox Code Playgroud)
如何按所需顺序对结果输出进行排序 - 如升序,降序,按名称排序等.特定于这些情况的答案就足够了.
你也可以自由地建议一个命令grep.