unix - strip words after matching character -
i have file there lines in pattern. want remove text after _. how do in unix?
x y z 1_2 3_4 5_6 i tried command:
$ sed 's/_.*//' but returns:
x y z 1 however want
x y z 1 3 5 thanks
just remove every _ + character:
$ echo "x y z 1_2 3_4 5_6" | sed 's/_\w//g' x y z 1 3 5 or, if want remove space, remove nonspace characters:
sed 's/_[^ ]*//g'
Comments
Post a Comment