• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Filtering content of command with grep

techinfozone

New Member
Joined
Feb 27, 2021
Messages
1 (0.00/day)
Location
Saudi Arabia
I am trying to filter out a the output of ssh-keyscan. The goal of this is to filter the output so I can use it in my python code to identify hosts connected to my VPN. Normally I would use grep to filter, one of my greps is filtering properly, but the other is not. The first grep is working to get just the ed25519 ID, but not sure why I am getting the SSH-2.0... lines also. The command I ran along with the output is below:
user@host# ssh-keyscan 10.xx.xx.xx | grep ed25519 | grep -v "#"
# 10.xx.xx.xx:22 SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
# 10.xx.xx.xx:22 SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
# 10.xx.xx.xx:22 SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
# 10.xx.xx.xx:22 SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
# 10.xx.xx.xx:22 SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
10.xx.xx.xx ssh-ed25519 <host key>

I need it to print only the ed25519 line. I have also tried AWK to filter, but still not getting the output I need.

Any idea how to filter only the ed25519 line?
 
Joined
Jun 21, 2021
Messages
3,038 (2.52/day)
System Name daily driver Mac mini M2 Pro
Processor Apple proprietary M2 Pro (6 p-cores, 4 e-cores)
Motherboard Apple proprietary
Cooling Apple proprietary
Memory Apple proprietary 16GB LPDDR5 unified memory
Video Card(s) Apple proprietary M2 Pro (16-core GPU)
Storage Apple proprietary onboard 512GB SSD + various external HDDs
Display(s) LG UltraFine 27UL850W (4K@60Hz IPS)
Case Apple proprietary
Audio Device(s) Apple proprietary
Power Supply Apple proprietary
Mouse Apple Magic Trackpad 2
Keyboard Keychron K1 tenkeyless (Gateron Reds)
VR HMD Oculus Rift S (hosted on a different PC)
Software macOS Sonoma 14.7
Benchmark Scores (My Windows daily driver is a Beelink Mini S12 Pro. I'm not interested in benchmarking.)
Well if you know the output is going to include "ssh-ed25519" you should grep on that.

Or pipe to that.

Or if you know it will be the last line of the output, pipe to the appropriate "tail" command.

Have you looked at the sed command?
 
Top