2

I came up with the following command: grep 'rtl' reg_list.txt | grep -E -o -n "id_\w+" reg_list.txt

The idea is that first grep lines which contains rtl content, then grep only the words which starts with id_ content. These data is in table, the first column contains rtl, the second column contains id_ data.

The problem is that, the result of first grep is not passed to the second one.

The reg_list.txt consists of different types of data, such as lines, tables with column and rows.

5

The result of the first grep is passed to the second grep, but since you give the second grep a filename, it will not read it (it would read from the file instead).

Instead:

grep 'rtl' reg_list.txt | grep -E -o -n 'id_[[:alnum:]]+'

I've also changed \w to [[:alnum:]] since \w is a PCRE regular expression. If your grep is GNU grep, you may keep \w and use grep -P instead.

  • a side question, is there a way to prioritize the pipe against the inputfile for a command? – αғsнιη Feb 9 '19 at 18:39
  • 2
    @αғsнιη With grep, you can make it read both by specifying /dev/stdin together with the name of a file (it will read from each in turn), but if you give it a filename, you can't have it ignore it. – Kusalananda Feb 9 '19 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.