gkmohit
gkmohit

Reputation: 710

grep to ignore the first character

If I have a bunch of lines that have :

//mainHtml = "https://
mainHtml = "https:
//https:www.google.com
public String ydmlHtml = "https://remando
aasdfa dsfadsf a asdfasd fasd fsdafsdaf

Now I want to grep only those lines which have "https:" in them, but they should NOT start with "//"

So far I have :

cat $javaFile | grep -e '\^\/ *https:*\'

where $javaFile is the file I want to look for the words. My output is a blank. Please help :)

Upvotes: 0

Views: 4586

Answers (2)

jaypal singh
jaypal singh

Reputation: 77085

You can use character class to negate the start of lines. We use -E option to use ERE or Extended Regular Expression.

grep -E '^[^/]{2}.*https' file

With your sample data:

$ cat file
//mainHtml = "https://
mainHtml = "https:
//https:www.google.com
public String ydmlHtml = "https://remando
aasdfa dsfadsf a asdfasd fasd fsdafsdaf

$ grep -E '^[^/]{2}.*https' file
mainHtml = "https:
public String ydmlHtml = "https://remando

You may also choose to write it without the -E option by saying:

grep '^[^/][^/].*https' file

Upvotes: 4

julienc
julienc

Reputation: 20305

In two steps:

grep -v '^//' | grep 'https:'
  • grep -v '^//' removes the lines starting with //
  • grep 'https:' gets the lines containing http:

Upvotes: 1

Related Questions