如何使用grep在用户以字符串形式输入的文件中查找确切的单词?
例如,我需要选择要查找的单词和要在其中查找的文件。我被告知我真的很接近了,但是有些事情并不像它应该的那样工作。我在Linux下使用的是bash shell。
以下是我到目前为止所做的工作:
#!/bin/bash
echo "Find the file you want to search the word in?"
read filename
echo "Enter the word you want to find."
read word1
grep $word1 $filename
我不太明白下面的if-语句实际上做了什么,从条件输出可能是什么的意义上说:
if linux-command-1 | linux-command-2 | linux-command-3 > /dev/null
我的理解是:
Linux 1被执行,它的输出被管道传输到2作为输入.
Linux 2用LC1的输入执行,它的输出被管道传输到3中.
Linux 3使用LC2的输入执行,它的输出被重定向到/dev/null,基本上不会出现。
,但是实际的if语句呢?是什么让它变得真实或错误呢?
为了进一步说明,下面是一个实际命令的示例:
if ps ax | grep -v gr
当我使用grep查找我需要的文本时,它将显示包含与给定模式匹配的行。
例如,
# grep -r ".*Linux" *
path0/output.txt:I hope you enjoyed working on Linux.
path1/output1.txt:Welcome to Linux.
path2/output2.txt:I hope you will have fun with Linux.
然后,我想编辑文件path2/output2.txt,因此,我输入了vim path2/output2.txt。
但是,我不认为这是一个有效的方法。
如何在grep之后复制
我们总是可以通过使用alias命令来查看alias值。
wolf@linux:~$ alias al='grep "$1" file.txt'
wolf@linux:~$ alias al
alias al='grep "$1" file.txt'
wolf@linux:~$
不幸的是,grep不能使用别名。不知道是什么问题。如果你知道问题和解决办法,请告诉我。
wolf@linux:~$ al
random text
abc def jkl
random text
abc ghi jkl
random text
wolf@li
在这两个for语句中,我都得到了以下错误:
./count_files.sh: line 21: [: too many arguments
./count_files.sh: line 16: [: too many arguments.
有人能帮我吗?
#!/bin/bash
files=($(find /usr/src/linux-headers-3.13.0-34/include/ -type f -name '[aeiou][a-z0-9]*.h'))
count=0
headerfiles=($(find /usr/src/linux-headers-3.
我试图让我的打印机(星Tsp-600)在Ubuntu12.04上工作。我发现这一页建议如下:
# get the cups development headers needed to compile the drivers
sudo apt-get install libcups2-dev libcupsimage2-dev
# download and extract the drivers from Star
wget http://www.starmicronics.com/Download/Drivers/starcupsdrv-3.0.0_Linux.zip
unzip starc
我在找一个脚本,工具...对于linux,它可以找到所有文件和所有文件中的关键字,类似于OSX Finder (我不是在寻找具有相同Finder界面的应用程序,而只是相同的工作)
例如,如果我在OSX Finder中搜索"linux“,我会得到:
linux (directory with linux name)
linux-2.4.0 (directory with linux in name)
...
memory.h (file with linux in text)
...
command.c (file with linux in text)
...
so-08-filesy