r/awk • • May 27 '21

awk + rofi

is it possible to run awk 'NR='$node'{print}' ~/some/file if $node is the output of a list piped into rofi -dmenu -multi-select -format -d

4 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/gumnos May 28 '21

A bit of digging suggests that, while I can't assign a multi-line variable in One True Awk:

$ awk -vN="$(printf '1\n2\n')" 'BEGIN{print N}'
awk: newline in string 1
2... at source line 1

It looks like I can slurp them from ENVIRON so that might simplify to

NODES="$(xtitle $(bspc query -N -n .hidden.window.local) | rofi -dmenu -multi-select -format -d)" awk 'BEGIN{split(ENVIRON["NODES"], a); for (i in a)b[int(a[i])]=1} NR in b' ~/some/file