Guillaume D
Guillaume D

Reputation: 2346

why this regex from git ls-remote is not working as it should be?

if I do :

echo From ssh://[email protected] | grep -oh From.* | grep -oh ssh.*git

I get what is excepted, which is:

ssh://[email protected]

but if I do:

git ls-remote | grep -oh From.* | grep -oh ssh.*git

I get the following output:

From ssh://[email protected]

Why?

Upvotes: 3

Views: 577

Answers (1)

choroba
choroba

Reputation: 242133

The "from" line goes to stderr, so it's ignored by grep. Redirect stderr to stdout to pipe it to grep:

git ls-remote 2>&1 | grep -o 'From.*' | grep -o 'ssh.*git'

Minor changes: -h is not needed when grepping stdin. Patterns quoted to prevent wildcard expansion by the shell.

Upvotes: 4

Related Questions