https://www.cnblogs.com/xy14/p/11735343.html
1 Overview
- Find content in multiple files
2. think doing
- purpose
- In multiple files, find content
- ready
- Before looking through the contents in a single file
- tool
- awk
- premise
- Have a fixed format file
- Finding the time required fields
-
example
# print $0 就一句话, 所以 不要 {} 也可以 > awk '{if($0 ~ <patter>){print $0}}' <fileName>
- premise
- grep
- premise
- This requirement is not so much
-
example
> cat <fileName> | grep <pattern>
- premise
- awk
- tool
- Before looking through the contents in a single file
- example
- Claim
- Find multiple files, containing rows 1
- And know which documents in the
-
file
# 得到 1 2 3 三个文件, 每个文件的内容, 是 1 到 10 > seq 1 10 > 1 > seq 1 10 > 2 > seq 1 10 > 3 # 可以用 循环写, 也不难对吧 > for i in {1..3};do seq 1 10 > ${i};done
- Claim
2. The idea of 1: cat | grep
-
command
> cat * | grep '1'
- result
-
Export
1 10 1 10 1 10
- Not feeling
- 1 found
- But do not know which file content distribution
-
3. Ideas 2: find | xargs grep
-
command
# 不理解 find 的同学, 可以用 ls 代替 # 我就不怎么理解 # -name 支持 通配符, 我的目录下只有三个文件, 所以也可以不带 > find . -type f -name "*" | xargs grep "1"
- result
-
Export
1:1 1:10 2:1 2:10 3:1 3:10
- The OK
- With the file name, ha ha
- Get
- With the file name, ha ha
-
4. Ideas
- Thinking
- find
- find
- To find a particular file
- The filename passed to grep
- grep
- Obtain multiple file names
- Find what files one by one
- Found, on the show
- find
- cat
- cat
- The contents of all files into the flow
- Will spread to grep
- grep
- Receive a stream
- File name has been lost
- Find Content
- You can only find the content
- Receive a stream
- cat
- find
- the difference
- grep can accept different things
- parameter
- After receiving the parameters, find files
- flow
- After receiving streams, which flow directly to the
- So the filename lost
- parameter
- Question 1: Why the xargs with grep on the own line number, but with a cat would not?
- Grep behind with more than one file name, will bring their own
- When a single file stream or not with
- Grep behind with more than one file name, will bring their own
- grep can accept different things