How to grep and execute a command (for every match)

前端 未结 6 1965
慢半拍i
慢半拍i 2020-12-14 00:18

How to grep in one file and execute for every match a command?

File:

foo
bar
42
foo
bar

I want to execute to execute for example

6条回答
  •  情话喂你
    2020-12-14 00:54

    What you really need is a xargs command. http://en.wikipedia.org/wiki/Xargs

    grep file foo | xargs date %s.%N
    

    example of matching some files and converting matches to the full windows path in Cygwin environment

    $ find $(pwd) -type f -exec ls -1 {} \; | grep '\(_en\|_es\|_zh\)\.\(path\)$' | xargs cygpath -w
    

提交回复
热议问题