LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-18-2018, 05:18 AM   #1
seehrum
LQ Newbie
 
Registered: Aug 2018
Posts: 15

Rep: Reputation: Disabled
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

output

1. when an unknown printer

22. took a galley of type and

3. scrambled it to

99. make a type specimen book. It has

89. survived not only five centuries,

21. but also the leap into

37. electronic typesetting, remaining 8essentially unchanged.

7. It was popularised in the
 
Old 08-18-2018, 05:22 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Well, if you need it, you must have made an attempt to resolve your requirement. So, what is your solution ?.
 
Old 08-18-2018, 05:29 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,306
Blog Entries: 3

Rep: Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720Reputation: 3720
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.
 
Old 08-18-2018, 05:34 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Trivial with sed.
 
Old 08-18-2018, 03:19 PM   #5
seehrum
LQ Newbie
 
Registered: Aug 2018
Posts: 15

Original Poster
Rep: Reputation: Disabled
I was able to separate the numbers from the letters

sed -r 's/([0-9])([a-zA-Z])/\1 \2/g; s/([a-zA-Z])([0-9])/\1 \2/g' input > output

observation, I wanted to apologize for my English :P
I'm not very fluent in English
who can help
I will be really grateful
 
Old 08-18-2018, 05:48 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
Old 08-20-2018, 06:44 AM   #7
seehrum
LQ Newbie
 
Registered: Aug 2018
Posts: 15

Original Poster
Rep: Reputation: Disabled
perfect! Thank you very much.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed space between captioned letters K-Veikko Other *NIX 5 05-15-2012 11:42 AM
adding letters to front and numbers to back of wordlist,bash perl or awk enteptain Programming 4 10-30-2011 09:35 PM
bash/sed/awk fill each line in text file with space to fixed length khairil Programming 11 01-09-2008 05:28 AM
sed or awk question - replace caps with small letters computera Linux - General 1 12-30-2003 04:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration