My program looks like this.
ALL=`cat $1 | grep -v '^#' | wc -l`
FINISHED="0"
for i in `cat $1 | grep -v '^#'`; do
echo "PROBE $i"
I will be doing some operation
FINISHED=`echo $FINISHED"+1"|bc`
I will run this script by giving a file name as parameter where a list of probes will be present.
I have 2 questions
What does grep -v '^#'
mean. I learnt that '^
is usually used to matching a particular string. But in the file name which I give there is no #
. Moreover I am getting the total number of probes for cat $1 | grep -v '^#' | wc -l
.
echo $FINISHED"+1"|bc
. Here any idea as to why the developer as added |bc
?
The grep command can search for a string in groups of files. When it finds a pattern that matches in more than one file, it prints the name of the file, followed by a colon, then the line matching the pattern.
In the simplest terms, grep (global regular expression print) is a small family of commands that search input files for a search string, and print the lines that match it.
grep searches input files for lines containing a match to a given pattern list. When it finds a match in a line, it copies the line to standard output (by default), or produces whatever other sort of output you have requested with options.
The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.
^
means "start of line"#
is the literal character #
-v
means "invert the match" in grep, in other words, return all non matching lines.Put those together, and your expression is "select all lines that do not begin with #
"
|
is the pipe character, it takes the output of the command on the left hand side, and uses it as the input of the command on the right hand side. bc
is like a command line calculator (to do basic math).
I would use this to exclude comments from the code I'm reading. So all comment lines start with # and I don't want to see them if there are too many of them.
grep -v '^#'
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