Question

How do I write a bash script that uses the 'egrep' command to list files containing...

How do I write a bash script that uses the 'egrep' command to list files containing either 'a' followed by 'g' or 'g' followed by 'a' (possibly with characters in between)?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

egrep - Extended Global Regular Expressions Print

egrep is used for matching a specified pattern. egrep is grep command as 'gerp -e' .

Multiple pattern matching is done with OR condition (|).

* - items will be matched zero or more than one times.

syntax:

egrep ' pattern1|pattern2' file name

Code:

$ egrep ' * (ag|ga)*' *.txt

or

$ egrep '(ag|ga)*' *.txt

Matches with more than one text files.

For specific file:

$ egrep ' * (ag|ga)*' file.txt

or

$ egrep '(ag|ga)*' file.txt

Add a comment
Know the answer?
Add Answer to:
How do I write a bash script that uses the 'egrep' command to list files containing...
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
  • Write a Bash script called hello that uses command line arguments to allow the user to...

    Write a Bash script called hello that uses command line arguments to allow the user to put two strings after the command name, when the script is being executed. These strings should represent a first and last name. The script should then write out a greeting to the user that includes the first and last name. Here is an example of how the script might work (the first line represents what the user types to launch the script): [user@HAL] hello...

  • Problem 4: Write a Bash script that removes all zero length ordinary files in the directory...

    Problem 4: Write a Bash script that removes all zero length ordinary files in the directory (including those in the sub-directories at all levels) passed as an optional argument. If you do not specify the directory argument, the script uses the current working directory as the default argument. This problem is for practicing bash programming skills. Though there is an easier way to achieve the goal with the find command, the find command is not allowed to appear in your...

  • Write a bash shell script to print the number of command line arguments and list of...

    Write a bash shell script to print the number of command line arguments and list of command line arguments 3. 12]

  • 1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories...

    1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script. Do not count recursively in subdirectories. Do not call any external Linux utilities such as “ls”. 2.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script....

  • Write a Bash script that removes all zero length ordinary files in the directory (including those...

    Write a Bash script that removes all zero length ordinary files in the directory (including those in the sub-directories at all levels) passed as an optional argument. If you do not specify the directory argument, the script uses the current working directory as the default argument. This problem is for practicing bash programming skills. Though there is an easier way to achieve the goal with find, find is not allowed to appear in your bash script.

  • write the bash script Write a script compress_large_files.sh. This script accepts one or more command line...

    write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...

  • Write a Bash script that removes all zero length ordinary files in the directory (including those...

    Write a Bash script that removes all zero length ordinary files in the directory (including those in the sub-directories at all levels) passed as an optional argument. If you do not specify the directory argument, the script uses the current working directory as the default argument. This problem is for practicing bash programming skills. Though there is an easier way to achieve the goal with find, find is not allowed to appear in your bash script. Post the screenshot of...

  • How do I write a bash shell script that encrypts a file by changing every letter...

    How do I write a bash shell script that encrypts a file by changing every letter except z to the next character in the alphabet. So a becomes b, b becomes c, and so on? z will be changed to a. Also, how do I write a bash shell script that reverses that?

  • Write a bash shell script to carry out each of the following tasks: What to Do:...

    Write a bash shell script to carry out each of the following tasks: What to Do: a. Safe Delete: When you use the “rm” command in Linux, it will delete the specified files, with no chance for recovering them back later. Write a script (called srm) that will safely delete the files passed to it as command-line arguments. For example, typing the command: “srm file1 file2 file3”, the script shall not actually delete these files, but instead it shall move...

  • Write a bash script that accepts one command line argument 'a' which is an integer between...

    Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. It should output a list of integers from 'a' and ending with '1' according to the following iteration rule. ( fx = x/2 if x is even; fx=3x+1 if x is odd )

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