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.
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: \.
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.
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 .
Use regular expressions:
grep -E '^ *//'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With