例如,使用grep命令查找日志文件中包含特定关键字的行。 package cn.juwatech.util;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class GrepUtil {public static void grep(String patter
public class GrepUtil { public static void grep(String pattern, String fileName) { String command = String.format("grep \"%s\" %s", pattern, fileName); try { Process process = Runtime.getRuntime().exec(command); BufferedReader reader = new BufferedReader(new InputStreamReader(process.get...
if a command-line -r is given, - otherwise. If fewer than two FILEs are given, assume -h. Exit status is 0 if any line is selected, 1 otherwise; if any error occurs and -q is not given, the exit status is 2. 三、选项说明 代码语言:javascript 代码运行次数:0 运行 AI代码解释 -a...
-D,--devices=ACTION how to handle devices, FIFOs and sockets;ACTIONis'read'or'skip' -r,--recursive like --directories=recurse-R,--dereference-recursivelikewise, but followallsymlinks--include=FILE_PATTERNsearch only files that match FILE_PATTERN--exclude=FILE_PATTERNskip filesanddirectories match...
This is equivalent to the -r option. --exclude=GLOB Skip any command-line file with a name suffix that matches the pattern GLOB, using wildcard matching; a name suffix is either the whole name, or a trailing part that starts with a non-slash character immediately after a slash (/) ...
For example, to display all the lines containing the string bash from the /etc/passwd file, you would run the following command: 例如,要显示/etc/passwd 文件中包含字符串 bash 的所有行,可以运行以下命令: 代码语言:javascript 复制 grep bash/etc/passwd ...
可以看到,当前目录下有一个 testfile 文件,它里面只有一行 "This is a test string." 字符串。 grep "string" testfile 命令会在 testfile 文件中查找 "string" 字符串,找到后打印出对应的行。 grep "string" "testfile" 命令也是在 testfile 文件中查找 "string" 字符串,即使用双引号把 testfile 括起来...
For example, to display all the lines containing the string bash from the /etc/passwd file, you would run the following command: 例如,要显示/etc/passwd 文件中包含字符串 bash 的所有行,可以运行以下命令: grep bash /etc/passwd 1. 输出应该是这样的: ...
However, you don’t needcathere (avoidUseless Use of Cat). Thegrepcommand is perfectly capable of reading files, so instead, you can use something like this to ignore lines that contain comments: $grep-v'^#'/etc/fstab If you want to send the output (without comments) to another file ...
grep - print lines matching a patterngrep [OPTIONS] PATTERN [FILE...] grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]