3
x=`src/lstat64 $TEST_DIR/$tmp.1 | sed -n -e '/ Links: /s/.*Links: *//p'`

In this script. I understand this part "/s/.*Links: *//p'" the only thing I don't understand is '/ Links: ' what does "/ " mean?

3 Answers 3

6

/ Links: / is an address filter. It means: "Apply the following operation only to those lines which match the filter." In this case the filter is a regex; it could also be a line number, a line area, a start regex and stop regex combination and even a "every n-th line" condition with some sed implementations.

3

You have a misunderstand. your command can be interpreted as:

sed - n -e '/pattern/ s/pattern/replace pattern/p'

So the first two / is belong to /pattern/, which meaning match a regex:

/regexp/
          Match lines matching the regular expression regexp.
2

the only thing I don't understand is '/ Links: '

Your sed expressions filters lines matching the pattern Links: (with a leading and trailing space) and performs the substitution

s/.*Links: *//

Moreover, using -n suppresses automatic printing of pattern space and p prints the current pattern space.

To summarize, the sed pipeline would print only the lines matching Links: in the input after performing the substitution s/.*Links: *//.

Quoting from man sed:

   -n, --quiet, --silent

          suppress automatic printing of pattern space


   p      Print the current pattern space.

   /regexp/
          Match lines matching the regular expression regexp.


   s/regexp/replacement/
          Attempt to match regexp against the pattern space.  If
          successful, replace that portion matched with replacement. The
          replacement may contain the special character & to refer to that
          portion of the pattern space which matched, and the special
          escapes \1 through \9 to refer to the corresponding matching
          sub-expressions in the regexp.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .