sed or awk? space between numbers and letters and line break
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
sed or awk? space between numbers and letters and line break
I need a command that separates the numbers from the letters, add points at the end of the numbers, and insert a line break
example
input
1when an unknown printer 22took a galley of type and 3scrambled it to 99make a type specimen book. It has 89survived not only five centuries, 21but also the leap into 37electronic typesetting, remaining 8essentially unchanged. 7It was popularised in the
Welcome. I'd use perl for that. You could do something with AWK by taking advantage of the fact that the Field Separator (FS) can be set to a pattern. However, it all comes down to what you have tried so far and where you are stuck. Please show what you have so far and where it is stuck so we know what approach you are working on and your approximate level.
So you understand sed concepts ok. Concentrate on what you care about - just the numerics. Use of repetition operator after a bracket expression indicates multiple of the same type - so "[0-9]+" means "1 or more digits". In addition to the capture groups you used, there is also the special case of "&" for what actually matched. You can also add newline characters. So try this instead.
Code:
sed -r 's/[0-9]+/\n\n&. /g'
It's not quite what you need, but shows the sort of sed features that will work for you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.