Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 在unix中从文件中获取行的一部分_Shell_Unix_Hp Ux - Fatal编程技术网

Shell 在unix中从文件中获取行的一部分

Shell 在unix中从文件中获取行的一部分,shell,unix,hp-ux,Shell,Unix,Hp Ux,我有一个名为temp.lst的文件,其内容如下: 1,13d0 < /hello/ux/PH/src/DEMO/dir/web/HelloWorld.java < /hello/ux/PH/src/USOURCES/java/frame/contain/ProcessResult.js < /hello/ux/PH/src/DEMO/dir/web/Hello.java < /hello/ux/PH/src/USOURCES/dir/web/World.java <

我有一个名为temp.lst的文件,其内容如下:

1,13d0
< /hello/ux/PH/src/DEMO/dir/web/HelloWorld.java
< /hello/ux/PH/src/USOURCES/java/frame/contain/ProcessResult.js
< /hello/ux/PH/src/DEMO/dir/web/Hello.java
< /hello/ux/PH/src/USOURCES/dir/web/World.java
< /hello/ux/PH/src/USOURCES/dir/web/Hey.java
我尝试使用cut命令,但这不是很通用。请帮助我,因为我是unix新手

sed -n 's@.*/USOURCES@USOURCES@p' temp.lst
-n
表示除非最后
p
明确告知,否则不要打印。剩下的只是从匹配的行中删除并打印它们

-n
表示除非最后
p
明确告知,否则不要打印。剩下的只是从匹配的行中删除并打印它们。

解决方案 你可以用和来表示

grep -o 'USOURCES.*' /tmp/so.txt
输出:

解释 -o,--仅匹配

   Print  only  the  matched  (non-empty) parts of a matching line, 
   with each such part on a separate output line.
解决方案 你可以用和来表示

grep -o 'USOURCES.*' /tmp/so.txt
输出:

解释 -o,--仅匹配

   Print  only  the  matched  (non-empty) parts of a matching line, 
   with each such part on a separate output line.

使用
awk

awk -F'USOURCES' 'NF>1{print FS $2}' temp.lst > final.lst

使用
awk

awk -F'USOURCES' 'NF>1{print FS $2}' temp.lst > final.lst