Question

Using regex, write a linux expression to search up the following in a .txt file to...

Using regex, write a linux expression to search up the following in a .txt file to match any IP address, the answer will show up in red:

Answer:
192.168.1.111
255.255.255.255
1.12.123.0
0.0.0.0

.txt file:
192.168.1.111
255.255.255.255
10.abc.1.13
192.168.1
1.12.123.0
18.19.20
255.255.255.
19211111111
.123.123.
...
0.0.0.0

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Linux expression to search any IP address in a .txt file using regex is :

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file.txt

In the above expression,

grep outputs the lines that contain the matching string

-o to only output the matching segment of the line

The squiggly brackets (e.g. { and }) indicate the number of instances of the match.

{1,3} requires that the previous character or character class must occur at least once, but no more than three times.

The character class [0-9] will successfully match against one or more numeric digits.

file.txt is the file that is to be searched for the pattern

Add a comment
Know the answer?
Add Answer to:
Using regex, write a linux expression to search up the following in a .txt file to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Linux, using sed, make the following changes in a txt file: Deletes trailing white space...

    In Linux, using sed, make the following changes in a txt file: Deletes trailing white space in each line. Every comma is followed by exactly one space. Every period is followed by exactly two spaces. Make the above into a script procedure called rmHTML().

  • 1. write a java program using trees(binary search treee) to read integers from input file( .txt)...

    1. write a java program using trees(binary search treee) to read integers from input file( .txt) and add +1 to each number that you read from the input file. then copy result to another (.txt) file. example: if inpu File has numbers like 4787 79434 4326576 65997 4354 the output file must have result of 4788 79435 4326577 65998 4355 Note: there is no commas in between the numbers. dont give images or theory please.

  • Using C++, Write a program that will search a file filled with numbers, and show the...

    Using C++, Write a program that will search a file filled with numbers, and show the largest number and the smallest number. The program will also count how many of the numbers are even (evenly divisible by two). Use the file data71.txt. File data71.txt numbers: 23 56 78 90 34 123 456 789 986 543 1104 2 4 7 543 124

  • Using linux Write one-line New Tab ands that determine and print the following desired output: 1....

    Using linux Write one-line New Tab ands that determine and print the following desired output: 1. The total word count in files file1.txt, file2.txt, and file3.txt combined (assume the three files exist in the current directory) 2. How many user accounts are not allowed to log in to the system. You need to calculate the number of users in file /etc/passwd that include /nologin on their line. 3. The name of the 6 largest files in/usr/bin , while suppressing any...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • computer networks help please !!! could someone help with the following tasks! ANY HELP WILL BE...

    computer networks help please !!! could someone help with the following tasks! ANY HELP WILL BE IMMENSELY APPRECIATED! THANKS. Task 1 In the following scenario, we would like to find out more information about a host that is on out network. Given an IP address we would like to search for additional information, we can start with obtaining the IP address off the default route. When running on a Linux VM, this like most likely to be the internal IP...

  • Write a c++ program in that file to perform a “Search and Replace All” operation. This...

    Write a c++ program in that file to perform a “Search and Replace All” operation. This operation consists of performing a case-sensitive search for all occurrences of an arbitrary sequence of characters within a file and substituting another arbitrary sequence in place of them. Please note: One of the biggest problems some students have with this exercise occurs simply because they don’t read the command line information in the course document titled “Using the Compiler’s IDE”. Your program: 1. must...

  • Using java: Store the files in .txt format and use the readByte() and writeByte() methods. File...

    Using java: Store the files in .txt format and use the readByte() and writeByte() methods. File encryption is the science of writing the contents of a file in a secret code. Write an encryption program that works like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code....

  • Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt...

    Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt formatted like this:      Tuesday we have Joe McHungry and Paul McHungry Wednesday we have Cindy Johnston and Paul Paulsen Thursday we have Amin Mirzaei and Atefeh Mirzaei gets turned into that: The McHungry on Tuesday Cindy and Paul on Wednesday The Mirzaei on Thursday 2)Write a script that takes as argument a port number. It returns the next port that is not assigned to...

  • Using Kali Linux, the Windows Linux Sub-System, or another Debian based Linux distribution, perform the following...

    Using Kali Linux, the Windows Linux Sub-System, or another Debian based Linux distribution, perform the following tasks based on the Linux Fundamentals lecture. For this lab, take screenshots for all major steps completed to illustrate that each task was successfully completed the same method as would be used for other labs). Tasks: 1. Create a new user named Billy Bob using the command linter face 2. Add Billy Bob to the sudoers group 3. Update and upgrade your Linux distribution...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT