0

Possible Duplicate:
bash tool to get nth line from a file

I want to build a small SSH manager for myself, and I want to hold all servers in a plain text file and I want to do something like:

ssh -i /home/edy/Documents/visually_ops.pem root@((N-th line of my file))

So I can use the ssh command and send it the N-th line of my plain text file, which is the host name. Would this be achievable?

Community
  • 1
  • 1
Eduard Luca
  • 6,514
  • 16
  • 85
  • 137
  • @KerrekSB not entirely. I already knew how to extract a line from a file, but not how to use it as *part* of a command, which Stephane covered in a nice manner. – Eduard Luca Sep 04 '12 at 11:56

1 Answers1

1

to print the n-th line of your host file you can use sed. For instance:

sed -n '3p' yourfile

will print the third line.

ssh -i /home/edy/Documents/visually_ops.pem root@$(sed -n '3p' yourfile)
Stephane Rouberol
  • 4,286
  • 19
  • 18