-2

I have an output that looks as below

- 0.1-1
- 0.1-2
- 0.1-3
- 0.1-6
- 0.1-7
- 0.1-9

How to use grep or something else so as to remove "-" and a space from the beginning.

0.1-1
0.1-2
0.1-3
0.1-6
0.1-7
0.1-9
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
meallhour
  • 13,921
  • 21
  • 60
  • 117

4 Answers4

2

With sed:

sed -e 's/^- //' input.txt

Or with GNU grep:

grep -oP '^- \K.*' input.txt
redneb
  • 21,794
  • 6
  • 42
  • 54
  • `-P` is available on fewer builds of GNU grep than `-o` is (introduced in a later release, and requires an extra compile-time option that modifies the set of library dependencies and thus isn't likely to be available on embedded systems). – Charles Duffy Sep 27 '16 at 15:02
1

You may use grep also,

grep -oE '[0-9].*' file
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
1

With awk:

awk '{print $2}' file
dawg
  • 98,345
  • 23
  • 131
  • 206
0

You can use cut to remove the first two columns of every line:

cut -c3- input.txt
galfisher
  • 1,122
  • 1
  • 13
  • 24