top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Overview About GREP Command ?

0 votes
451 views

What is Grep Command?

The grep command allows you to search one file or multiple files for lines that contain a pattern.

If Grep is not installed in your system you can install by using the following command.

$ sudo apt-get install grep         #Debian/Ubuntu

$ sudo yum install grep             #RHEL/CentOS/Fedora

Syntax For Grep Commands

grep [options] pattern [files]

Option Description

-b Display the block number at the beginning of each line.
-c Display the number of matched lines.
-h Display the matched lines, but do not display the filenames.
-i Ignore case sensitivity.
-l Display the filenames, but do not display the matched lines.
-n Display the matched lines and their line numbers.
-s Silent mode.
-v Display all lines that do NOT match.
-w Match whole word.

Here Some of the examples for using Grep

1)How to Search a Given word in a single File

grep "String_name" filename

2)How to Search a String in Multiple File

grep "string" FILE_PATTERN

The Above example will used to search the string in multiple files.For Example,We have 2 text files named as textfile1 and textfile2.

Now the following command will use to search the string in these two text files

  grep "search_string"  text*

3)How will do Case insensitive search

Using -i option you can do the case insensitive search.

Syntax

grep -i  "string"  Filename

4)How search a string in recursively

Using -r option will do the recursive search.

grep -r  "string" *

5)How to count the number of Matches

Using -c option you can count the number of matches.

grep -c "string" Filename
posted Aug 25, 2014 by Manish Tiwari

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button


Related Articles

What is man command ?

man is the interface used to view the system's reference manuals.

man is the system's manual viewer; it can be used to display manual pages, scroll up and down, search for occurrences of specific text, and other useful functions.

To use the man command, at the Unix prompt, enter:

man search_topic

For example you need to find information about grep.You can use the following command and get the grep detail information

man grep

Some of the General options

-h, --help Print a help message and exit.
-V, --version Display version information and exit.
-C file, --config-file=file Use configuration file file rather than the default of ~/.manpath.
-d, --debug Print debugging information.
-D, --default This option, when used, is normally specified as the first option; it resets man's behaviour to its default. Its use is to reset those options that may have been set in $MANOPT. Any options that follow -D will have their usual effect.
--warnings[=warnings] Enable warnings from the groff text formatter. This may be used to perform sanity checks on the source text of manual pages. warnings is a comma-separated list of warning names; if it is not supplied, the default is "mac". See the "Warnings" node in the groff info page for a list of available warning names.

Check here for more details about options - http://www.computerhope.com/unix/uman.htm

Video tutorial for Man Command

https://www.youtube.com/watch?v=xpJ8NyeOgbQ

READ MORE

What is use for Wget Command?

wget utility is the best option to download files from internet.
wget can pretty much handle all complex download situations including large file downloads, recursive downloads, non-interactive downloads, multiple file downloads etc.

Some of the examples for how to download using wget

1) How to download a single file with using wget

$ wget http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

The above example downloads a single file from internet and stores in the current directory.

2) How to download and store with a different File name Using wget -O

$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701

3) How to Specify Download Speed / Download Rate Using wget –limit-rate

$ wget --limit-rate=200k http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

In the above example, the download speed is limited to 200k.

4) How to Continue the Incomplete Download Using wget -c

$ wget -c http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

5) How to Download in the Background Using wget -b

$ wget -b http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

6) How to Test Download URL Using wget –spider

$ wget --spider DOWNLOAD-URL

7)How to Increase Total Number of Retry Attempts Using wget –tries

$ wget --tries=75 DOWNLOAD-URL

8) How to Download Multiple Files / URLs Using Wget -i

First, store all the download files or URLs in a text file as:

$ cat > download-file-list.txt
URL1
URL2
URL3
URL4

Next, give the download-file-list.txt as argument to wget using -i option as shown below.

$ wget -i download-file-list.txt

9)How to Download a Full Website Using wget –mirror

$ wget --mirror -p --convert-links -P ./LOCAL-DIR WEBSITE-URL

10) How to Quit Downloading When it Exceeds Certain Size Using wget -Q

$ wget -Q5m -i FILE-WHICH-HAS-URLS

11)FTP Download With wget

$ wget --ftp-user=USERNAME --ftp-password=PASSWORD DOWNLOAD-URL

12)How to Reject Certain File Types while Downloading Using wget –reject

$ wget --reject=gif WEBSITE-TO-BE-DOWNLOADED

13)Log messages to a log file instead of stderr Using wget -o

$ wget -o download.log DOWNLOAD-URL
READ MORE

What is nano?

nano is a text editor for Unix-like computing systems or operating environments using a command line interface. It emulates the Pico text editor, part of the Pine email client, and also provides additional functionality.

GNU nano is a small and friendly text editor. Besides basic text editing, nano offers many extra features like an interactive search and replace, go to line and column number, auto-indentation, feature toggles, internationalization support, and filename tab completion.

Nano has a pseudo-graphical layout that makes it a little easier to jump right into.

Command for Starting nano editor

nano newfile

Editor Window
enter image description here

Command line Options

+LINE,COLUMN
Start at line number LINE and column number COLUMN (at least one of which must be specified) instead of the default of line 1, column 1.
-?
Same as -h, --help.
-A, --smarthome
Make the Home key smarter. When Home is pressed anywhere but at the very beginning of non-whitespace characters on a line, the cursor will jump to that beginning (either forwards or backwards). If the cursor is already at that position, it will jump to the true beginning of the line.
-B, --backup
When saving a file, back up the previous version of it to the current filename suffixed with a ~.
-C , --backupdir=
Set the directory where nano puts unique backup files if file backups are enabled.
-D, --boldtext
Use bold text instead of reverse video text.
-E, --tabstospaces
Convert typed tabs to spaces.
-F, --multibuffer
Enable multiple file buffers, if available.
-H, --historylog
Log search and replace strings to ~/.nano_history, so they can be retrieved in later sessions, if nanorc support is available.
-I, --ignorercfiles
Don't look at SYSCONFDIR/nanorc or ~/.nanorc, if nanorc support is available.
-K, --rebindkeypad
Interpret the numeric keypad keys so that they all work properly. You should only need to use this option if they don't, as mouse support won't work properly with this option enabled.
-L, --nonewlines
Don't add newlines to the ends of files.
-N, --noconvert
Don't convert files from DOS/Mac format.
-O, --morespace
Use the blank line below the titlebar as extra editing space.

More Reference click here -> http://mintaka.sdsu.edu/reu/nano.html

READ MORE

What is Shell?

In Unix, the shell is a program that interprets commands and acts as an intermediary between the user and the inner workings of the operating system.

It is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems.

It makes basic facilities such as multitasking and piping easy to use, and it adds useful file-specific features such as wildcards and I/O redirection.

Shell Prompt:

The prompt, $, which is called command prompt, is issued by the shell. While the prompt is displayed, you can type a command.

The shell reads your input after you press Enter. It determines the command you want executed by looking at the first word of your input. A word is an unbroken set of characters. Spaces and tabs separate words.

Simple Example

$date
Mon Sep  8 14:03:04 UTC 2014

Types of Shell

There are four common shells in use:

 · the Bourne shell 
 · the Korn shell 
 · the C shell 
 · the Bash shell (Bourne Again Shell)

Reletionship Diagram for above four shells
enter image description here

SELECTING A SHELL

When you are provided with a UNIX account,the system administrator chooses a shell for you.

To find out which shell was chosen for you, look at your prompt.

If you have a $ prompt, you’re probably in a Bash, Bourne or a Korn shell.

If you have a % prompt, you’re probably in a C shell.

chsh is the utilitity which allows you to change your default login shell.

It prompts you for the full pathname of the new shell,which is then used as your shell for subsequent logins.

  • In order to use chsh, you must know the full pathnames of the three shells.

Here they are:
Bourne /bin/sh
Bash /bin/bash
Korn /bin/ksh
C /bin/csh

READ MORE
...