Reputation: 44588
Please explain this sed command?
sed -n "s/[^>]*>/ /gp"
What is gp?
Upvotes: 2
Views: 2019
Reputation: 112
I was typing up a long explanation, but Brian beat me to it. To clarify a tiny bit, the "p" prints the modified / matching line. The "-n" in your command line tells sed to "not print the file". Combined with the "p", it works kinda like grep, but within the scope of the script (ie, anything it changes/matches).
Upvotes: 1
Reputation: 26210
It looks for non-greater-than characters preceding a greater-than symbol, and changes all of them to a single space. Thus, it will convert this input (where I've used _ to indicate a space):
foo>_bar> b
x>>_a
to
___b
___a
As Mark notes, "g" means global, and "p" means "print the line".
Upvotes: 5
Reputation: 838326
g
means global: i.e. replace all occurences, not just the first.p
means to print the modified line. Otherwise due to the -n
switch it would not be printed.The command finds all lines containing at least one >
and prints some spaces followed by the text after the final >
. The number of spaces printed is the number of >
in the line.
For example if this line is in the input file:
123>456>789
Then this is printed:
789
Upvotes: 3