Issue
113728482180.18408400639521053213728482180.18534013377161235313728482180.18527849814511801413728482180.12680711716571988513728482180.40802725786530114613728482180.039221670254883746713728482180.42748179436369843813728482180.45107192556631565913728482180.43916947404834661013728482180.12677684033447337
How do I add text (in this case a \n
) 11 characters before the position that matches 0.
?
I want to end up with something like:
113728482180.18408400639521053
213728482180.18534013377161235
313728482180.18527849814511801
413728482180.12680711716571988
513728482180.40802725786530114
613728482180.039221670254883746
713728482180.42748179436369843
813728482180.45107192556631565
913728482180.43916947404834661
013728482180.12677684033447337
I possible, I would also like to solve the following. The first digit of each line is a counter (1, 2, 3, ..., 10, ..., 10000, ...). The last digit from the 9th line (which is 1) should also be included in the 10th line so as to this line begin with 10, rather than 0. This would also be necessary for 1000s, 10000s and 100000s.
Is it possible? Something like, for the lines 1-9, the offset would be 11, for the lines 10-99, the offset would be 12, for the lines 100-999, the offset would be 13, and so on.
For the example above, the last two lines would become:
913728482180.4391694740483466
1013728482180.12677684033447337
The counter is sequential. For larger numbers, in the order of hundreds and thousands, just adding the newline 11 characters before the match would end up like this in the case of 10000s:
213728482180.43916947404831000
313728482180.12677684033441000
But the aim is to get:
1000213728482180.4391694740483
1000313728482180.1267768403344
Solution
try this: (gnu sed)
sed -r 's/([^.]{12}\.)/\n\1/2g' file
example:
kent$ sed -r 's/([^.]{12}\.)/\n\1/2g' a
113728482180.18408400639521053
213728482180.18534013377161235
313728482180.18527849814511801
413728482180.12680711716571988
513728482180.40802725786530114
613728482180.039221670254883746
713728482180.42748179436369843
813728482180.45107192556631565
913728482180.43916947404834661
013728482180.12677684033447337
Answered By - Kent Answer Checked By - Timothy Miller (WPSolving Admin)