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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -