Skip to main content
Suggestions for standard sed. Remove awkward use of "-n" and "/gp".
Source Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k

The use of grep is redundant, sed can do the same. The problem is in the use of * that matchwhich also match 0 spaces. With GNU sed, you have tomay use \+ instead:

iostat | sed -n '/hdisk1/s/ \+/ /gp'

If yourOr, with standard sed do:

iostat | sed -e '/hdisk/!d' -e 's/ \{2,\}/ /g'

to delete all lines that does not supportscontain the substring \+hdisk metachar, then doand to replace all runs of two or more spaces with single spaces, or

iostat | sed -ne '/hdisk1/s!d' -e 's/   */ /gp'g'

The use of grep is redundant, sed can do the same. The problem is in the use of * that match also 0 spaces, you have to use \+ instead:

iostat | sed -n '/hdisk1/s/ \+/ /gp'

If your sed do not supports \+ metachar, then do

iostat | sed -n '/hdisk1/s/  */ /gp'

The use of grep is redundant, sed can do the same. The problem is in the use of * which also match 0 spaces. With GNU sed, you may use \+ instead:

iostat | sed -n '/hdisk1/s/ \+/ /gp'

Or, with standard sed:

iostat | sed -e '/hdisk/!d' -e 's/ \{2,\}/ /g'

to delete all lines that does not contain the substring hdisk, and to replace all runs of two or more spaces with single spaces, or

iostat | sed -e '/hdisk1/!d' -e 's/   */ /g'
Source Link
enzotib
  • 53.5k
  • 14
  • 126
  • 106

The use of grep is redundant, sed can do the same. The problem is in the use of * that match also 0 spaces, you have to use \+ instead:

iostat | sed -n '/hdisk1/s/ \+/ /gp'

If your sed do not supports \+ metachar, then do

iostat | sed -n '/hdisk1/s/  */ /gp'