user2335924
user2335924

Reputation: 55

set of word from the same line to several lines in bash

Here is my line:

^MClone: 10% done.^MClone: 11% done.^MClone: 12% done.^MClone: 13% done.^MClone: 14% done.^MClone: 15% done.^MClone: 16% done.

I would like to split each Clone: xx% per line

As expected result:

Clone: 10%
Clone: 11%
Clone: 12%
etc..

each line should contains each pourcentage instead of having all in only one line.

Upvotes: 0

Views: 55

Answers (3)

Avinash Raj
Avinash Raj

Reputation: 174696

This will also work,

sed 's/\^M//g;s/done.//g;s/% /%\n/g' file

Upvotes: 0

choroba
choroba

Reputation: 241808

Use sed. ^M is represented by \r:

sed -e 's/\r/\n/g' -e 's/ done\.//g' file

Upvotes: 2

fedorqui
fedorqui

Reputation: 289535

You can use grep for this:

$ grep -o 'Clone: [0-9]*%' file
Clone: 10%
Clone: 11%
Clone: 12%
Clone: 13%
Clone: 14%
Clone: 15%
Clone: 16%

This looks for strings on the format Clone: <numbers>% and prints them.

From man grep:

-o, --only-matching

Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.

Upvotes: 4

Related Questions