Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to grep lines that start with double forward slash in Linux command line?

How do I grep lines in a file that start with double forward slash from the Linux command line? The double forward slashes may have spaces before it, but only spaces before it and no other types of characters.

e.g.

shell_prompt: ls
shell_prompt: grep .....? file_name

Sorry was being unobservant, I didn't notice something that existed before the // characters other than the space. Problem solved. Will award to the guy that answered first.

like image 822
FinalForm Avatar asked Jul 01 '11 20:07

FinalForm


People also ask

How do I grep forward slash in Linux?

The forward slash is not a special character in grep, but may be in tools like sed, Ruby, or Perl. You probably want to escape your literal periods, though, and it does no harm to escape the slash. This should work in all cases: \.

What does double forward slash mean in Linux?

Actually it means nothing and is ignored. This often happens when output from multiple places is combined and it isn't clear who's job it is to add the slashes, so both parties do it and you end up with two of them. Semantically in the case of a directory path is has no meaning and will be ignored by most programs.

How do you grep with additional lines?

For BSD or GNU grep you can use -B num to set how many lines before the match and -A num for the number of lines after the match. If you want the same number of lines before and after you can use -C num .


2 Answers

Use regular expressions:

grep -E '^ *//'
like image 101
Michał Trybus Avatar answered Oct 08 '22 01:10

Michał Trybus


grep "//" jquery.js

will find all lines that contain //. Which if your looking for comments, what you might be interested in.

grep "^//" jquery.js

will find just lines that start with //.

It might me worth your while to start looking into Regular Expressions.

like image 23
Matt Sieker Avatar answered Oct 08 '22 01:10

Matt Sieker