fzf to return combination of input fields

370 Views Asked by At

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

There are 1 best solutions below

0
jhnc On BEST ANSWER

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