简体   繁体   English

来自BASHRC的解析功能

[英]Parsing functions from BASHRC

I'm using BASHRC to store alot of my daily routines, and overtime its gotten cluttered, and now there are some duplicate. 我正在使用BASHRC来存储我的许多日常工作,并且加班时间变得混乱不堪,现在有些重复了。 Was wondering if there's a way with SED\\AWK\\grep to parse all of the functions into array and then remove duplicate. 想知道SED \\ AWK \\ grep是否有办法将所有函数解析为数组,然后删除重复项。

sample of bashrc with duplicate: 具有重复项的bashrc样本:

  function action1(){
    /usr/bin/operate $1
    }
   function action2(){
    /usr/bin/perform $1 $2
    }
   function action1(){
    /usr/bin/operate $1
    }

Thanks, 谢谢,

Roy 罗伊

If that's REALLY what your input file looks like then all you need is: 如果这真的是您输入文件的外观,那么您需要做的就是:

$ awk '$1=="function"{unq=!seen[$2]++} unq' file
  function action1(){
    /usr/bin/operate $1
    }
   function action2(){
    /usr/bin/perform $1 $2
    }

If it's not then edit your question to provide some truly representative sample input and expected output. 如果不是,请编辑您的问题以提供一些真正具有代表性的样本输入和预期输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM