Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 5th, 2005, 12:14 PM   #1
Wejmok Chorg
Newbie
 
Join Date: Jul 2005
Posts: 1
Rep Power: 0 Wejmok Chorg is on a distinguished road
Please Help Newbie

Hello,

I have a log file, which I want to use as a word list. Problem is, there's no space between the words and the numbers to which the words are linked.

For instance, I need to change

called20:12,18

to

called 20:12,18

by adding a space between the words and the numbers.

sed's info file tells me that replace-strings get interpreted litterally on the right hand side.

Thus, as info telle me, sed s/[a-zA-Z][0-9]/[a-z][A-Z]\ \[0-9]/g testfile produces "calle[a-z][A-Z] [0-9]0:12,18"

Can someone tell me how I can search my file for all instances of letter-then-number, and replace them with letter-then-space-then-number?

Thank you very much.
Wejmok Chorg is offline   Reply With Quote
Old Jul 5th, 2005, 1:28 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Just search for a subpattern containing one or more alphabetics, such as ([a-zA-Z]+), then replace it with the subpattern plus a space. That presumes that your example always represents your data.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 5th, 2005, 3:35 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Here's a copy of a CLI screen
C:\DOCUME~1\David\Desktop>type filter.txt
s/\([a-zA-Z]*\)/\1 /

C:\DOCUME~1\David\Desktop>type sedtest.txt
caller20:20:20
called1:30:03

C:\DOCUME~1\David\Desktop>ssed -f filter.txt sedtest.txt > results.txt

C:\DOCUME~1\David\Desktop>type results.txt
caller 20:20:20
called 1:30:03

C:\DOCUME~1\David\Desktop>
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 5th, 2005, 4:19 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Just to clarify:

When you want to keep certain sections of the document you're running the regex on, you enclose them in parentheses (brackets - ( and ) ), as DaWei shows. You then use these by using "\1", "\2" etc. in the replace string.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jul 7th, 2005, 9:31 AM   #5
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
Well, there's tr as well.

cat filename | tr -s ';'  ' '  | tr -s ','  ' '  > newfilename
jim mcnamara is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC