0

I have a vector of following numbers

1_0.011100  1_0.003500  1_0.013700  0_0.011500

I would like unix code that selects only the number before the under score.

The outcome should be

1  1  1  0

and could you please make it applicable to run it over 500 columns?

4

This will work for as many columns as you need:

sed 's/_[0-9.]\+//g'
  • @MarwahSoliman please stop having irrelevant discussions in the comments. If you have a question about something else, then post a new question. In the meantime, if one of these answers solved the issue you asked about, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. – terdon Mar 21 '17 at 19:03
1
perl -lpe '$_ = join $", /(\d+)_/g'
perl -lne '$,=$"; print /(\d+)_/g'
  • do I have to apply both lines? – Marwah Soliman Mar 21 '17 at 18:05
  • No. They are independent solutions in their own right. Take your pick. – user218374 Mar 21 '17 at 18:06
  • how can I apply your code on columns from 8 to 509 what should I write – Marwah Soliman Mar 21 '17 at 18:10
  • 1
    @MarwahSoliman your question didn't mention anything about specific columns. Either edit your question, or ask a new one. You might want to take the tour or visit the help center to understand how this site works. – terdon Mar 21 '17 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.