LinuxQuestions.org
Visit Jeremy's Blog.
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, 03:51 AM   #1
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 135

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, 03:55 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
what kind of regexp did you try? dot is usually \. or [.] just see documentation about that.
 
Old 04-27-2014, 03:56 AM   #3
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
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, 04:45 AM   #4
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 135

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, 04:54 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
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, 05:00 AM   #6
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:48 PM
[SOLVED] simple regex problem doughyi8u Programming 4 01-08-2012 08: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 02:10 AM
[SOLVED] What's Wrong with the RegEx [Simple] thund3rstruck Programming 2 04-04-2011 12:04 PM
simple regex not so simple (perl) ludeKing Programming 5 03-02-2005 03:29 AM


All times are GMT -5. The time now is 10:08 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration