开发者

concatenate a string to the end of every output line in bash/csh

开发者 https://www.devze.com 2023-02-09 12:51 出处:网络
In bash command line, if I run \"find . -name \'abc*\' \", it prints out a list of filenames like abc1

In bash command line, if I run "find . -name 'abc*' ", it prints out a list of filenames like

abc1
abc2
abc3

How can I pipe it with echo or ot开发者_如何学编程her command, so that i get this output:

abc1   ok
abc2   ok
abc3   ok


find . -name 'abc*' | sed 's/$/\tok/' | column -t

sed appends the string <Tab>ok to each line, and column formats the output nicely (you can just skip this, if you don't need it).


I tend to write:

whatever | while read line; do echo $line ok; done

That might be overkill for something this simple, but it becomes the simplest thing to do if you want to do more complicated things with the line. And it doesn't involve remembering how to make sed work!


With GNU find,

find . -name "abc*" -printf "%f ok\n"


Simply:

$ find . -name 'abc*' | xargs -I {} echo {} OK


Pipe it through sed, is one way:

 | sed -e 's/\(^.*\)/\1   ok/'


You could use xargs:

find -iname "abc" | xargs -IREPL echo REPL ok


Have a look at the paste standard command. Or for each element of what find shall get you manually echo the filename and the result of a function on that filename.

Can you please tell what you finally want to do?


Use something like this :

find . -name "abc*" -exec echo "{} - ok" \;


find . -name 'abc*' -exec echo {}' OK' \; | column -t
0

精彩评论

暂无评论...
验证码 换一张
取 消