我有一个路径列表,但我只关心某些路径。例如。
/nwsys/release/conf/reu/xprofd.cfg4
/nwsys/release/conf/save/xprofd.cfg.rtcr1
/nwsys/release/conf/amcxml4.conf
如何仅从/nwsys/release/conf/anyfile.anyextension返回
grep "/nwsys/release/conf/"
答案 0 :(得分:2)
你可以使用egrep:
egrep '/nwsys/release/conf/.*\.' file
/nwsys/release/conf/reu/xprofd.cfg4
/nwsys/release/conf/save/xprofd.cfg.rtcr1
/nwsys/release/conf/amcxml4.conf
其中:
cat file
/nwsys/release/conf/reu/xprofd.cfg4
/nwsys/release/conf/save/xprofd.cfg.rtcr1
/nwsys/release/conf/amcxml4.conf
/nwsys/release/conf/anything
答案 1 :(得分:2)
$ egrep '^/nwsys/release/conf/[^/]+\.[^/]+$' file
/nwsys/release/conf/amcxml4.conf
答案 2 :(得分:1)
喜欢这个吗?
awk -F/ '{print $1,$2,$3,$4,$NF}' OFS=/ file
/nwsys/release/conf/xprofd.cfg4
/nwsys/release/conf/xprofd.cfg.rtcr1
/nwsys/release/conf/amcxml4.conf
将路径更改为所有文件的三个级别。
或者你正在寻找:
awk -F/ 'NF<6' file
/nwsys/release/conf/amcxml4.conf
打印具有3个级别的路径的行。