如何过滤文本文件以删除所有内容并仅保留其中的路径?例如:
dslkjcblasdjncklasdnlc /asdds/ads/adss/sdf.jpg asljdascuashn sdkm
/sdf/dsf/dsf/dfs/sdfs.txt ,nbaskhdnasm.ddslkjcblasdjncklasdnlc
/asdds/ads/adss/sdf.jpg asljdascuashn sdkm /sdf/dsf/dsf/dfs/sdfs.txt
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /asdds/ads/adss/sdf.jpg
asljdascuashn sdkm /34/34/dsf/dfs/sdfs.txt
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /asdds/ads/adss/sdf.jpg
asljdascuashn sdkm /sdf/dsf/dsf/dfs/sdfs.txt
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /sd/df/fg/fgsdf.jpg asljdascuashn
sdkm /sdf/dsf/34/dfs/sdfs.txt ,nbaskhdnasm.ddslkjcblasdjncklasdnlc
/asdds/ads/adss/sdf.jpg asljdascuashn sdkm /sdf/dsf/dsf/dfs/sdfs.txt
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /qw2/sd23/adss/sdf.jpg
asljdascuashn sdkm /34/34/dsf/dfs/sdfs.png
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /asdds/ads/adss/sdf.jpg
asljdascuashn sdkm /sdf/dsf/dsf/dfs/sdfs.txt
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /wre/ads/adss/sdf.nii
asljdascuashn sdkm /sdf/dsf34/dsf/dfs/sdfs.pmb
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /asdds/ads/adss/sdf.jpg
asljdascuashn sdkm /sdf/dsf/dsf/dfs/sdfs.txt
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /34/ads/34/sdf.jpg asljdascuashn
sdkm /34/dsf/dsf/34/sdfs.dbt ,nbaskhdnasm.ddslkjcblasdjncklasdnlc
/asdds/ads/adss/sdf.jpg asljdascuashn sdkm /sdf/dsf/dsf/dfs/sdfs.txt
,nbaskhdnasm.ddslkjcblasdjncklasdnlc /34/34/34/sdf.zip asljdascuashn
sdkm /sd34f/dsf/dsf/34/sdfs.tar.gz ,nbaskhdnasm.d
我怎样才能删除所有内容并只保留路径,以便我得到:
/asdds/ads/adss/sdf.jpg
/sdf/dsf/dsf/dfs/sdfs.txt
/asdds/ads/adss/sdf.jpg
/sdf/dsf/dsf/dfs/sdfs.txt
/asdds/ads/adss/sdf.jpg
/34/34/dsf/dfs/sdfs.txt
/ads/adss/sdf.jpg
/sdf/dsf/dsf/dfs/sdfs.txt
/sd/df/fg/fgsdf.jpg
/sdf/dsf/34/dfs/sdfs.txt
/asdds/ads/adss/sdf.jpg
/sdf/dsf/dsf/dfs/sdfs.txt
/qw2/sd23/adss/sdf.jpg
/34/34/dsf/dfs/sdfs.png
/asdds/ads/adss/sdf.jpg
/sdf/dsf/dsf/dfs/sdfs.txt
/wre/ads/adss/sdf.nii
/sdf/dsf34/dsf/dfs/sdfs.pmb
/asdds/ads/adss/sdf.jpg
/sdf/dsf/dsf/dfs/sdfs.txt
/34/ads/34/sdf.jpg
/34/dsf/dsf/34/sdfs.dbt
/asdds/ads/adss/sdf.jpg
/sdf/dsf/dsf/dfs/sdfs.txt
/34/34/34/sdf.zip
/sd34f/dsf/dsf/34/sdfs.tar.gz
答案1
使用 GNU grep 的-o
选项,并假设文件路径按空格分割:
grep -o '/[^ ]*' < input