我有一个文件 file1
它包含:
< 16 ./lnx/apps/vlc/tsconf_1.0-11_all.deb
< 16 ./lnx/apps/vlc/vlc
< 2000 ./lnx/apps/vlc/vlc-nox_2.0.8-1_i386.deb
< 16 ./lnx/apps/vlc/vlc-plugin-notify_2.0.8-1_i386.deb
< 32 ./lnx/apps/vlc/vlc-plugin-pulse_2.0.8-1_i386.deb
< 16 ./lnx/cmds/64bit_ubuntu_add_i386
< 16 ./lnx/cmds/acroread_dl
< 16 ./lnx/cmds/dl_from_gdrv
< 16 ./lnx/cmds/dpkg_install_list_in_txt_file
< 16 ./lnx/cmds/find_and_replace
< 16 ./lnx/cmd/pearl_script.ps1
< 16 ./lnx/cmds/rm_using_find
< 16 ./lnx/cmds/wget_dl_whl_ws
我想删除 <
之间的所有内容和 ./
(或介于 \n
和 ./
之间)不包括 ./
,所以输出如下:
./lnx/apps/vlc/tsconf_1.0-11_all.deb
./lnx/apps/vlc/vlc
./lnx/apps/vlc/vlc-nox_2.0.8-1_i386.deb
./lnx/apps/vlc/vlc-plugin-notify_2.0.8-1_i386.deb
./lnx/apps/vlc/vlc-plugin-pulse_2.0.8-1_i386.deb
./lnx/cmds/64bit_ubuntu_add_i386
./lnx/cmds/acroread_dl
./lnx/cmds/dl_from_gdrv
./lnx/cmds/dpkg_install_list_in_txt_file
./lnx/cmds/find_and_replace
./lnx/cmd/pearl_script.ps1
./lnx/cmds/rm_using_find
./lnx/cmds/wget_dl_whl_ws
我试过这些命令(它们的输出是准确的输入文件):
$ sed -n '/</,/ ./ p' file1
$ sed 's/< .* " ."/./' file1
$ sed -e 's/<\n[^ .]>/<\n.>/g' file1
$ sed -e 's/\(<\).*\(.\)/\1\2/' file1
可能这只是一件简单的事情,但我是 sed/awk/tr/grep/find 命令的新手。
最佳答案
$ sed 's/[^.]*//' file
./lnx/apps/vlc/tsconf_1.0-11_all.deb
./lnx/apps/vlc/vlc
./lnx/apps/vlc/vlc-nox_2.0.8-1_i386.deb
./lnx/apps/vlc/vlc-plugin-notify_2.0.8-1_i386.deb
./lnx/apps/vlc/vlc-plugin-pulse_2.0.8-1_i386.deb
./lnx/cmds/64bit_ubuntu_add_i386
./lnx/cmds/acroread_dl
./lnx/cmds/dl_from_gdrv
./lnx/cmds/dpkg_install_list_in_txt_file
./lnx/cmds/find_and_replace
./lnx/cmd/pearl_script.ps1
./lnx/cmds/rm_using_find
./lnx/cmds/wget_dl_whl_ws
关于bash - Linux/庆典 : remove text between two chars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22518041/