sed use case: Filter without editing

雨点打透心脏的1/2处 2021-12-17 07:07 202阅读 0赞

if we want to filter with sed pattern and just print the filtered lines without any further editing , we can do it like this

  1. ls -a1 ~ | sed -ne "/^\./p"

This command will print all dir entries that starts with “.”

  1. ls -a1 ~ | sed -ne "/^\./p" | sed -ne "/bash/p"

I want to find meta files related to bash, so I got the result:

  1. .bash_history
  2. .bash_logout
  3. .bashrc

we can view each file content by

  1. ls -a1 ~ | sed -ne "/^\./p" | sed -ne "/bash/p" | xargs -n 1 less

delete file and directories except “term.sh” and “test.cpp”

  1. ls | sed -e "/^term.sh$/d" | sed -e "/^test.cpp$/d" | xargs -n 1 rm -rf

show contents of all status file in current directory tree

  1. find . -iname status | xargs -n 1 less

转载于:https://www.cnblogs.com/long123king/p/3754581.html

发表评论

表情:
评论列表 (有 0 条评论,202人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Use Case 和User Story

    Use Case(用例)和User Story(用户故事)他们之间究竟有什么联系和区别,还是他们本身就是一个物种的两种不同叫法而已,究竟哪个好或是哪个不好,这些问题的讨论见诸

    相关 Use Case框图

    Use Case 框图用于显示系统功能(或称为使用案例)与提供或接收系统信息的人或系统(或称为角色)之间的相互关系,也即该框图需显示从用户角度出发对系统提出的要求。所以它可供用