在Linux中显示包含某些字符的整行

时间:2021-12-30 22:22:25

I am wondering if there is a way to display the entire line in a data file containing specific characters in linux? For example searching for "577789999" in a file.txt should display me the line such as below

我想知道是否有办法在包含linux中特定字符的数据文件中显示整行?例如,在file.txt中搜索“577789999”应该显示如下所示的行

577789999    adef   YTM   777888

2 个解决方案

#1


1  

that's what grep is for

这就是grep的用途

grep 577789999 file.txt

you might want to restrict the pattern to occur only in the beginning of the line:

您可能希望将模式限制为仅在行的开头发生:

grep ^577789999 file.txt

#2


0  

Generaly, you might use grep like that : grep "the researched string" "filename"

通常,你可以使用这样的grep:grep“研究字符串”“文件名”

It'll tells you at which line you're string is, and if you search it on "*" (All files in the current dir), it tells you in which file you're string is ;)

它会告诉你你在哪一行你是字符串,如果你在“*”(当前目录中的所有文件)上搜索它,它会告诉你你在哪个文件中是字符串;)

#1


1  

that's what grep is for

这就是grep的用途

grep 577789999 file.txt

you might want to restrict the pattern to occur only in the beginning of the line:

您可能希望将模式限制为仅在行的开头发生:

grep ^577789999 file.txt

#2


0  

Generaly, you might use grep like that : grep "the researched string" "filename"

通常,你可以使用这样的grep:grep“研究字符串”“文件名”

It'll tells you at which line you're string is, and if you search it on "*" (All files in the current dir), it tells you in which file you're string is ;)

它会告诉你你在哪一行你是字符串,如果你在“*”(当前目录中的所有文件)上搜索它,它会告诉你你在哪个文件中是字符串;)