Computer Science, asked by suhanakarishma7393, 1 year ago

Write a regex grep that lists all the files in the current directory that was created in nov and are txt files.

Answers

Answered by rajawatbhavi
1

A good example is parsing a html file to extract <img> tags of a

web document. If the image locations are available, then we can write a script to

automatically download these images to a location we specify. Looking for tags like

<img> is a form of searching for a pattern. Pattern searches are widely used in many

applications like search engines. A regular expression(regex) is defined as a pattern

that defines a class of strings. Given a string, we can then test if the string belongs to this

class of patterns. Regular expressions are used by many of the unix utilities like grep,

sed, awk, vi, emacs etc. We will learn the syntax of describing regex later.

Pattern search is a useful activity and can be used in many applications. We are already

doing some level of pattern search when we use wildcards such as *. For example,

> ls *.c

Lists all the files with c extension or

ls ab*

lists all file names that starts with ab in the current directory. These type of commands

(ls,dir etc) work with windows, unix and most operating systems. That is, the command ls

will look for files with a certain name patterns but are limited in ways we can describe

patterns. The wild card (*) is typically used with many commands in unix. For example,

cp *.c /afs/andrew.cmu.edu/course/15/123/handin/Lab6/guna

copies all .c files in the current directory to the given directory

Unix commands like ls, cp can use simple wild card (*) type syntax to describe specific

patterns and perform the corresponding tasks. However, there are many powerful unix

utilities that can look for patterns described in general purpose notations. One such utility

is the grep command...

Similar questions