awk/sed print from pattern to end of file

 

By using awk/sed command we can print text from a given pattern to end of file.

I have file with names.txt with following content:

uk
us
india
obama
putin
vatican

With following sed/awk commands I will show how to print text from line “india” to end of file:

With sed:

Syntax:

$ sed -n '/Pattern/,$p' inputFile

Example:

$ sed -n '/india/,$p' namex.txt

Output:

india
obama
putin
vatican

With awk:

Syntax:

$ awk '/Pattern/,0' inputFile

Example:

$ awk '/india/,0' names.txt

Output:

india
obama
putin
vatican

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s