Brain  Crist

Brain Crist

1597518000

How to Grep for Multiple Strings and Patterns

grep is a powerful command-line tool that allows you to searches one or more input files for lines that match a regular expression and writes each matching line to standard output.

In this article, we’re going to show you how to use GNU grep to search for multiple strings or patterns.

Grep Multiple Patterns

GNU grep supports three regular expression syntaxes, Basic, Extended, and Perl-compatible. When no regular expression type is specified, grep interpret search patterns as basic regular expressions.

To search for multiple patterns, use the OR (alternation) operator.

The alternation operator | (pipe) allows you to specify different possible matches that can be literal strings or expression sets. This operator has the lowest precedence of all regular expression operators.

The syntax for searching multiple patterns using the grep basic regular expressions is as follows:

grep 'pattern1\|pattern2' file...

Always enclose the regular expression in single quotes to avoid the interpretation and expansion of the meta-characters by the shell.

When using basic regular expressions, the meta-characters are interpreted as literal characters. To keep the special meanings of the meta-characters, they must be escaped with a backslash (\). This is why we are escaping the OR operator (|) with a slash.

To interpret the pattern as an extended regular expression, invoke grep the -E ( or --extended-regexp) option. When using extended regular expression, do not escape the | operator:

grep -E 'pattern1|pattern2' file...

For more information about how to construct regular expressions, check our article Grep regex .

Grep Multiple Strings

Literal strings are the most basic patterns.

In the following example, we are searching for all occurrences of the words fatalerror, and critical in the Nginx log error file:

grep 'fatal\|error\|critical' /var/log/nginx/error.log

If the string you are searching includes spaces, enclose it in double quotation marks.

Here is the same example using the extended regular expression, which eliminates the need to escape the operator |

grep -E 'fatal|error|critical' /var/log/nginx/error.log

By default, grep is case sensitive. This means that the uppercase and lowercase characters are treated as distinct.

To ignore case when searching, invoke grep with the -i option (or --ignore-case):

grep -i 'fatal\|error\|critical' /var/log/nginx/error.log

When searching for a string, grep will display all lines where the string is embedded in larger strings. So if you were searching for “error”, grep will also print the lines where “error” is embedded in larger words, such as “errorless” or “antiterrorists”.

To return only those lines where the specified string is a whole word (enclosed by non-word characters), use the -w ( or --word-regexp) option:

grep -w 'fatal\|error\|critical' /var/log/nginx/error.log

Word characters include alphanumeric characters (a-z, A-Z, and 0-9) and underscores (_). All other characters are considered as non-word characters.

For more details about grep options, visit our article Grep command .

#string #linuxize #multiple strings #patterns

What is GEEK

Buddha Community

How to Grep for Multiple Strings and Patterns
Brain  Crist

Brain Crist

1597518000

How to Grep for Multiple Strings and Patterns

grep is a powerful command-line tool that allows you to searches one or more input files for lines that match a regular expression and writes each matching line to standard output.

In this article, we’re going to show you how to use GNU grep to search for multiple strings or patterns.

Grep Multiple Patterns

GNU grep supports three regular expression syntaxes, Basic, Extended, and Perl-compatible. When no regular expression type is specified, grep interpret search patterns as basic regular expressions.

To search for multiple patterns, use the OR (alternation) operator.

The alternation operator | (pipe) allows you to specify different possible matches that can be literal strings or expression sets. This operator has the lowest precedence of all regular expression operators.

The syntax for searching multiple patterns using the grep basic regular expressions is as follows:

grep 'pattern1\|pattern2' file...

Always enclose the regular expression in single quotes to avoid the interpretation and expansion of the meta-characters by the shell.

When using basic regular expressions, the meta-characters are interpreted as literal characters. To keep the special meanings of the meta-characters, they must be escaped with a backslash (\). This is why we are escaping the OR operator (|) with a slash.

To interpret the pattern as an extended regular expression, invoke grep the -E ( or --extended-regexp) option. When using extended regular expression, do not escape the | operator:

grep -E 'pattern1|pattern2' file...

For more information about how to construct regular expressions, check our article Grep regex .

Grep Multiple Strings

Literal strings are the most basic patterns.

In the following example, we are searching for all occurrences of the words fatalerror, and critical in the Nginx log error file:

grep 'fatal\|error\|critical' /var/log/nginx/error.log

If the string you are searching includes spaces, enclose it in double quotation marks.

Here is the same example using the extended regular expression, which eliminates the need to escape the operator |

grep -E 'fatal|error|critical' /var/log/nginx/error.log

By default, grep is case sensitive. This means that the uppercase and lowercase characters are treated as distinct.

To ignore case when searching, invoke grep with the -i option (or --ignore-case):

grep -i 'fatal\|error\|critical' /var/log/nginx/error.log

When searching for a string, grep will display all lines where the string is embedded in larger strings. So if you were searching for “error”, grep will also print the lines where “error” is embedded in larger words, such as “errorless” or “antiterrorists”.

To return only those lines where the specified string is a whole word (enclosed by non-word characters), use the -w ( or --word-regexp) option:

grep -w 'fatal\|error\|critical' /var/log/nginx/error.log

Word characters include alphanumeric characters (a-z, A-Z, and 0-9) and underscores (_). All other characters are considered as non-word characters.

For more details about grep options, visit our article Grep command .

#string #linuxize #multiple strings #patterns

Samanta  Moore

Samanta Moore

1623835440

Builder Design Pattern

What is Builder Design Pattern ? Why we should care about it ?

Starting from **Creational Design Pattern, **so wikipedia says “creational design pattern are design pattern that deals with object creation mechanism, trying to create objects in manner that is suitable to the situation”.

The basic form of object creations could result in design problems and result in complex design problems, so to overcome this problem Creational Design Pattern somehow allows you to create the object.

Builder is one of the** Creational Design Pattern**.

When to consider the Builder Design Pattern ?

Builder is useful when you need to do lot of things to build an Object. Let’s imagine DOM (Document Object Model), so if we need to create the DOM, We could have to do lot of things, appending plenty of nodes and attaching attributes to them. We could also imagine about the huge XML Object creation where we will have to do lot of work to create the Object. A Factory is used basically when we could create the entire object in one shot.

As **Joshua Bloch (**He led the Design of the many library Java Collections Framework and many more) – “Builder Pattern is good choice when designing the class whose constructor or static factories would have more than handful of parameters

#java #builder #builder pattern #creational design pattern #design pattern #factory pattern #java design pattern

I am Developer

1597559012

Multiple File Upload in Laravel 7, 6

in this post, i will show you easy steps for multiple file upload in laravel 7, 6.

As well as how to validate file type, size before uploading to database in laravel.

Laravel 7/6 Multiple File Upload

You can easily upload multiple file with validation in laravel application using the following steps:

  1. Download Laravel Fresh New Setup
  2. Setup Database Credentials
  3. Generate Migration & Model For File
  4. Make Route For File uploading
  5. Create File Controller & Methods
  6. Create Multiple File Blade View
  7. Run Development Server

https://www.tutsmake.com/laravel-6-multiple-file-upload-with-validation-example/

#laravel multiple file upload validation #multiple file upload in laravel 7 #multiple file upload in laravel 6 #upload multiple files laravel 7 #upload multiple files in laravel 6 #upload multiple files php laravel

What is difference between String and string in C#

Are you confused about System.String and string in C#? What is the difference between String and string in C#? And how to choose between string and System.String? In this article, I am going to show you all the differences between string and System.String in C## with code examples. .

What is the difference between System.String and string in C#?

Basically, there is no difference between string and String in C#. “string” is just an alias of System.String and both are compiled in the same manner. String stands for System.String and it is a .NET Framework type. “string” is an alias in the C## language for System.String. Both of them are compiled to System.String in IL (Intermediate Language), so there is no difference.

#c# #string #string and string

I am Developer

1597470037

Laravel 7 Multiple Image Upload with Preview

Here, i will show you how to upload multiple image with preview using ajax in laravel.

Laravel 7 Ajax Multiple Image Upload with Preview

Just follow the below steps and upload multiple images using ajax with showing preview in laravel applications:

  • Install Laravel Fresh Setup
  • Setup Database Credentials
  • Create Route
  • Generate Controller By Command
  • Create the blade view
  • Start Development Server

https://www.tutsmake.com/laravel-7-6-ajax-multiple-image-upload-with-preview-e-g/

#laravel multiple image upload with preview #laravel multiple image validation #display multiple images in laravel #laravel multiple file upload #multiple image upload in laravel 6 #ajax image upload and preview with laravel