Regex-Part-2: Regex with special characters ( ^ and $ )

Narendra P
A free video tutorial from Narendra P
Automation Engineer with Scripting Languages and Tools
4.5 instructor rating • 5 courses • 30,783 students

Learn more from the full course

Complete Bash Shell Scripting

Automate repetitive tasks with Bash Shell Scripting to save valuable time

18:20:28 of on-demand video • Updated November 2020

  • Students will be able to understand shell scripting concepts
  • Students will be able to understand unix filters like awk, cut and sed
  • This course is helpful to Automate repetitive tasks in different Admin areas like Linux Admins, Middleware Admins, Database Admins, DevOps Admin and AWS Cloud Admins
  • This course is helpful to write basic to advance level shell scripts
English [Auto] Prince in our previous video we created some patterns with the help of some special characters like you know space tab. Dot dot means for any character matching then start star means judo or more characters for your preceding letter. Then slash question mark. None not one matching then slash plus one or more matching. Then finally we have seen slash also means to escape you a special purpose of all these characters. Right now the thing is you have so many special characters. Now we discuss only some of them. Now here we are going to discuss two more special characters on these are very very important in your real time. They are like carrot and symbol. So what is the use of carrot and dollar symbol right. See basically carrot is used to match any word at this topping off your given line. Let's say I have a file call in this week. Right now I will do one thing. Let me modify this file. I am going to write something like put this that in this line. No I suppose I am going to such a line which consist of what I want to bring to the lines which are having put right. Let me do this first. So how many lines you are getting two lines. But what I am doing is I want to get the line which are having but only are the starting of your line. Now see the output what you are getting but what is there in two lines. But in first anyhow somewhere in secondary hard very first note character means what all the warriors or something if that what is their very first in a given line then only that line will print. I mean you are searching for the lines which are having a good war. Are they starting. Not only would what you can go with any word right now same way. Let's say first if you have are fighting okay. No I am going to such a line which consists of suppose part I'm going to print to the lines which are having part work. Let me bring to them first so you have two places. Part that's where getting two lines. No I want to get the lines which are having part ward at the ending in the given line to get the lines which are having part ward at the end. Right. You are to take your searching board at the end. You have to take dialer then see the output what you are getting you are getting the line which is having part at the end. So that is the usage of a dollar if you are looking for some word right here you are looking for some lines which are having part work especially at the end. Then you have to use part your searching more than dollar symbol right now find no saved. SIEGEL So let me show you your file first so yeah let me open this file. So I want to clear some empty Landsman because my next intention is find out in empty lines let me clear suppose some 3 4 empty lines now see that as of now. Whatever the file you are having these the file. Now my requirement is I want to bring to the lines which are empty. So there is a shortcut like start with nothing and with nothing there is a meaning with this symbol now if you order the output. See this many gaps you are getting means that many empty lines you have in your file. Not generally in your real time right. Well working with some files if there are any empty lines you want to delete them. So if you want to delete any line you know what is the syntax for that based on searching word or somebody if I want the first line. How do you this index like then it will get into your first line but I wonder delete the lines which are empty which are empty so delete these lines now see that what you are getting you are getting output without any empty lines if you wander delayed permanently the empty lines. You know what a general file or source file. Just use I if I option right now open your file and see the content what is there. Now you don't have any empty lines. This is a very very important one in all real time deleting empty lines permanently. These are syntax simply this is the meaning to find out empty lines. So you are searching for empty lines and that lines you are deleting. So I find I mean permanently or deleting. So that is the uses of your carrot and dollar symbol and a combination of carrot and dollar no let's say I will do something I'm going to add some somewhat more let me bring to the lines which are having carrot symbol. Suppose if I want to do that what I can do hyphen in carrot bring to the lines which are having carrot symbol but see what you are getting auditing all the lengths. So basically the purpose of getting these what all those touching body home that word should be there starting. You don't have anything right. That's where all lines are matching. But if you want to match character with the character itself you know Canada is a special character so you need to remove that special purpose by using a skip symbol. Now see the output the same way I want to get the lines which are having only a dollar symbol not for ending with something only the lines which are having dollar for dollar purposes such something at the end of your line. I mean such of the lines which are having some popular what at the end. But I don't want to go in that way. I don't want to use my special purpose of character. I want to just match like a quasi vehicles to be I want to match like that. Then you have to remove your special purpose of your dollar by placing your escape symbol. That's a okay. So is already we discussed about in our previous video escape symbol same purpose we are using here right. Okay guys we'll see some more special characters to create your patterns and to use in regular expressions of your set. Come on in later videos. Okay. Thank you for watching this video.