执行字符串搜索的shell脚本中的行
pcline=`grep -w "$file1" $file2` # grep for file1 in file2 contents
如果我回显命令,命令的输出如下所示
grep -w run /home/rajesh/rootfs.layoutExpectedlrwxrwxrwx 1 root root 3 Aug 28 runActuallrwxrwxrwx 1 root root 7 Aug 28 bin/run-partslrwxrwxrwx 1 root root 3 Aug 28 run-rwxr-xr-x 1 root root 303 Aug 28 tests/aes/run.sh-rwxr-xr-x 1 root root 445 Aug 28 tests/auto_ui/run.sh-rwxr-xr-x 1 root root 320 Aug 28 tests/available_memory/run.sh-rwxr-xr-x 1 root root 308 Aug 28 tests/Fonts/run.sh-rwxr-xr-x 1 root root 309 Aug 28 tests/HTML_config_page/run.sh-rwxr-xr-x 1 root root 361 Aug 28 tests/ipc/run.sh-rwxr-xr-x 1 root root 304 Aug 28 tests/JsON/run.sh-rwxr-xr-x 1 root root 303 Aug 28 tests/log4cplus_cpp/run.sh-rwxr-xr-x 1 root root 301 Aug 28 tests/log4cplus_c/run.sh-rwxr-xr-x 1 root root 751 Aug 28 tests/msm_basic/run.sh-rwxr-xr-x 1 root root 472 Aug 28 tests/res_man_dependency/run.sh-rwxr-xr-x 1 root root 465 Aug 28 tests/res_man_ipc/run.sh-rwxr-xr-x 1 root root 789 Aug 28 tests/res_man_multi_process/run.sh-rwxr-xr-x 1 root root 469 Aug 28 tests/res_man_private_clIEnt/run.sh-rwxr-xr-x 1 root root 492 Aug 28 tests/res_man_public_clIEnt/run.sh-rwxr-xr-x 1 root root 311 Aug 28 tests/virt_mem_config/run.shlrwxrwxrwx 1 root root 6 Aug 28 var/run]
我尝试的技巧是添加一个空白,这在我的输入文件中得到保证,这在控制台中有效,但在分配给变量时则不行.
grep " tests/aes/run.sh" /home/rajesh/rootfs.layout
在脚本中排队
pcline=`grep \"" $file1"\" $file2` # grep for file1 in file2 contents
如果我在此脚本中犯了任何错误,请告诉我.
解决方法 你可以像这样使用egrep:egrep "(^| )$file1( |$)" "$file2"
如果file1 =“run”,则上面的命令将匹配以行开头或空格开头的字符串运行,后跟空格或行结束.
总结以上是内存溢出为你收集整理的linux – grep完全单词匹配(-w)不适用于文本文件中的文件路径全部内容,希望文章能够帮你解决linux – grep完全单词匹配(-w)不适用于文本文件中的文件路径所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)