将”fzf to return combination of input fields”翻译为中文: “fzf 返回输入字段的组合”

huangapple go评论60阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月24日 19:51:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定