Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8761473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:17:42+00:00 2026-06-13T15:17:42+00:00

I have a string in a bash script that contains a line of a

  • 0

I have a string in a bash script that contains a line of a log entry such as this:

Oct 24 12:37:45 10.224.0.2/10.224.0.2 14671: Oct 24 2012 12:37:44.583 BST: %SEC_LOGIN-4-LOGIN_FAILED: Login failed [user: root] [Source: 10.224.0.58] [localport: 22] [Reason: Login Authentication Failed] at 12:37:44 BST Wed Oct 24 2012

To clarify; the first IP listed there “10.224.0.2” was the machine the submitted this log entry, of a failed login attempt. Someone tried to log in, and failed, from the machine at the 2nd IP address in the log entry, “10.224.0.58”.

I wish to replace the first occurrence of the IP address “10.224.0.2” with the host name of that machine, as you can see presently is is “IPADDRESS/IPADDRESS” which is useless having the same info twice. So here, I would like to grep (or similar) out the first IP and then pass it to something like the host command to get the reverse host and replace it in the log output.

I would like to repeat this for the 2nd IP “10.224.0.58”. I would like to find this IP and also replace it with the host name.

It’s not just those two specific IP address though, any IP address. So I want to search for 4 integers between 1 and 3, separated by 3 full stops ‘.’

Is regex the way forward here, or is that over complicating the issue?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:17:43+00:00Added an answer on June 13, 2026 at 3:17 pm

    Replace a fixed IP address with a host name:

    $ cat log | sed -r 's/10\.224\.0\.2/example.com/g'
    

    Replace all IP addresses with a host name:

    $ cat log | sed -r 's/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/example.com/g'
    

    If you want to call an external program, it’s easy to do that using Perl (just replace host with your lookup tool):

    $ cat log | perl -pe 's/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/`host \1`/ge'
    

    Hopefully this is enough to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: # Generate bash script $bashScript = #!/bin/bash`n; $bashScript += [string]::Join(`n,
I have this bash script on the server that runs every hour, via cron.
I have a Bash script that builds a string to run as a command
I have a string in a Bash shell script that I want to split
I have a bash script that has as a variable a urlencoded string, that
I have string that look like Array that fetched from other webservice like this
I have some problems with a PHP script that calls a Bash script.... in
I'm trying to write a bash script that can edit itself. The line of
I have bash script that I use regularly in my job to automate a
then, elif, else statement that I have programmed in a bash script. I know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.