Reputation: 569
I have an entry in /etc/services file.
abcde 25354/tcp
I need to take the port number of the entry abcde
inside my shell script. How to do so?
Upvotes: 0
Views: 1124
Reputation: 54325
awk '/^imap / { split($2, a, "/"); print a[1]; }' /etc/services
You will need to replace imap with abcde, or whatever you are really looking for. You might even need to extend the pattern like ^imap .*tcp
You may also like
getent services imap
Which produces:
imap 143/tcp imap2
Upvotes: 3
Reputation: 368964
Using grep
:
grep ^abcde /etc/services | grep -o '[0-9]*'
The first grep is to get line with abcde
, the second is to get digits part only.
Upvotes: 0