LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-27-2014, 02:51 AM   #1
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 234

Rep: Reputation: Disabled
a simple regex problem


This should be easy but I cannot wrap my brains around it.
I tried to use regex on this:
33 eidkei eikeiek eiekek
34 eiekek eiekek ekeek
35 eiekek ekekek ekekke

I want to turn it into:
3.3 eidkei eikeiek eiekek
3.4 eiekek eiekek ekeek
3.5 eiekek ekekek ekekke

\d\d makes a match but how do I put a dot in between the numbers?
 
Old 04-27-2014, 02:55 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
what kind of regexp did you try? dot is usually \. or [.] just see documentation about that.
 
Old 04-27-2014, 02:56 AM   #3
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Code:
bash-4.3$ echo "33 eidkei eikeiek eiekek " | sed 's/\(^.\)/\1\./' 
3.3 eidkei eikeiek eiekek
 
1 members found this post helpful.
Old 04-27-2014, 03:45 AM   #4
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 234

Original Poster
Rep: Reputation: Disabled
I have been using the text-editor Geany. I have been trying all along and I have found a workaround. Not slick. But it works.

First. Replace the first 3's with dots:
Search for:3
Replace with:.

You get:
.3 eidkei eikeiek eiekek
.4 eiekek eiekek ekeek
.5 eiekek ekekek ekekke

Then another regex.
Search for:[/.]
Replace with:3.

Thank you for your replies.
 
Old 04-27-2014, 03:54 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Here are some alternatives:
Code:
echo "33 eidkei eikeiek eiekek " | sed 's/^./&./'

echo "33 eidkei eikeiek eiekek " | awk -F "" '$1=$1"."' OFS=""

echo "33 eidkei eikeiek eiekek " | ruby -ne 'puts $_.sub(/^./,"\\&.")'
 
Old 04-27-2014, 04:00 AM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
I love losing to grail because I always learn something.
 
  


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
A simple regex help Mimouch Linux - Newbie 3 01-23-2014 09:48 PM
[SOLVED] simple regex problem doughyi8u Programming 4 01-08-2012 07:55 PM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
[SOLVED] What's Wrong with the RegEx [Simple] thund3rstruck Programming 2 04-04-2011 11:04 AM
simple regex not so simple (perl) ludeKing Programming 5 03-02-2005 02:29 AM

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

All times are GMT -5. The time now is 07:05 PM.

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