bash - Linux/庆典 : remove text between two chars

标签 bash replace sed awk tr

我有一个文件 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/

相关文章:

bash - 在 Ubuntu 上查找并删除 DOS 行结尾

c++ - C++中的BASH数组和变量的变量

perl - 如何使用 shell(awk、sed 等)删除文件中的前两列

sed - 使用 sed 将行号插入文件

JAVA 替换除可变字符串以外的所有内容

java - 正则表达式替换电子邮件

java - 从电话号码字符串条目中删除所有特殊字符,除了仅出现在第一位的 +

linux - 剪切不作为变量工作

Bash 中的正则表达式 : not wanting to include directories

bash - $做什么? $0 $1 $2 在 shell 脚本中是什么意思?