英文:
fzf to return combination of input fields
问题
I have this command:
echo -e "a 1 10\nb 2 20\nc 3 30\nd 4 40" | fzf -m --bind 'enter:execute(echo {1}:{2})+abort' | tr -d "'"
Input data looks like:
a 1 10
b 2 20
c 3 30
d 4 40
How do I modify fzf part to return space separated strings in the format of {1}:{2}
but for all selections? Expected output result (if we select lines beginning with a
and b
) is:
a:1 b:2
I tried changing fzf placeholder to {+1}:{+2}
but it first echoes all first fields and then all second fields instead of combining them.
Thank you.
英文:
I have this command:
echo -e "a 1 10\nb 2 20\nc 3 30\nd 4 40" | fzf -m --bind 'enter:execute(echo {1}:{2})+abort' | tr -d "'"
Input data looks like:
a 1 10
b 2 20
c 3 30
d 4 40
How do I modify fzf part to return space separated strings in format of {1}:{2}
but for all selections? Expected output result (if we select lines begining with a
and b
) is:
a:1 b:2
I tried changing fzf placeholder to {+1}:{+2}
but it first echoes all first fields and then all second fields instead of combining them.
Thank you.
答案1
得分: 1
查看fzf手册,我没有看到太多关于格式化其输出的功能。
由于您的数据似乎是以空格分隔的字段,因此很容易对fzf
的输出进行后处理:
# 在结果之间添加空格,没有终止符
... | fzf -m | awk '{ $0 = (NR > 1 ? " " : "") $1 }' ORS=
# 在每个结果之后添加空格
... | fzf -m | awk 'NF=2 OFS=:' ORS=' '
# 在结果之间添加空格,使用换行符终止
... | fzf -m | awk 'NF=2 OFS=:' | xargs
英文:
Looking at the fzf manual, I don't see much functionality for formatting its output.
As your data seems to be whitespace-delimited fields, it is quite easy to postprocess fzf
's output:
# space between results, no terminator
... | fzf -m | awk '$0=(NR>1?" ":"")$1":"$2' ORS=
# space after each result
... | fzf -m | awk NF=2 OFS=: ORS=" "
# space between results, newline terminator
... | fzf -m | awk NF=2 OFS=: | xargs
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论