Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Create on-the-fly hostname lists for ssh tab completion' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create on-the-fly hostname lists for ssh tab completion
Authored by: CarlRJ on Mar 24, '08 01:53:09PM
For what it's worth, the core bit of the process:
cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["
can be reduced from five commands and four pipe to two commands and one pipe:
sed -e 's/^  *//' -e '/^#/d' -e 's/[, ].*//' -e '/\[/d' ~/.ssh/known_hosts | sort -u
This also handles comment lines in known_hosts (starting with "#") and duplicates which do not follow each other (by using "sort -u" in place of "uniq").

[ Reply to This | # ]
Create on-the-fly hostname lists for ssh tab completion
Authored by: corienti on Mar 24, '08 04:00:44PM

VERY nice, CarlRJ! I am impressed - and you got rid of a classical "useless use of cat" as well! Sed is a beautiful thing...



[ Reply to This | # ]