Issue
currently I am working on a school assignment on Linux using Vim where I have to write a script that displays the user that is currently logged in, the time and date, and list only the IP address of the Nic card. I have everything working except for the IP address part. If anyone could help I would appreciate it greatly.
Edit to include the code I have at the moment.
#!/bin/bash
Time=$(date)
IP=$(ifconfig ens33)
echo "The following user is currently logged in $USER"
echo ""
echo "The current time is $Time"
echo ""
echo "The IP information is $IP"
Solution
You can filter the result of ifconfig
using awk
like this (IPv4):
$ ifconfig ens33 | awk '/inet addr/{print substr($2, 6)}'
Result:
10.10.xx.xx
inet addr:
represents IPv4 address.
inet6 addr:
represents IPv6 address.
Answered By - Azeem Answer Checked By - Gilberto Lyons (WPSolving Admin)