Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace only First Occurrence--BBedit

Status
Not open for further replies.

Ingo444

Technical User
Mar 2, 2005
4
US
It doesn't look like the BBedit forum gets much action, so--rightly or wrongly-- I'm posting this here.

I'm new to this, so please excuse my ignorance...each line of text has several commas, I need to replace just the first occurrence of a comma with a tab. I don't know the proper expression for replacing just the first comma. Thank you.
 
This should be one, From: (.*?),(.*) - To: $1\t$2 - or \1 or \\1.
If that doesnt work, see if you can post a shot of the BBedit search window.

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
I couldn't get it to work. I'd like to replace the first comma in line 1, then the first comma in line 2 and so on until the end of the file. I don't know how to attach the screen shot to this post (sorry), but the search window has a "search for:" box and a "replace with:" box. Also, I'm using Grep (trying to anyway). Thanks.
 
why don't you post a couple of lines - I assume they're text lines.

btw, 'grep' is not the right tool for replacement. Look into sed.

FYI, 'grep' stands for GlobalRegularExpressionPrint as in sed-lingo: 'g/re/p'.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Code:
sed -e "s/^\([^,]*\),/\1`/bin/echo '\t'`/g" yourInputFile

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
the posted sed should do the trick for ya.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
The three sample lines are below. In each line, I want to replace just the first comma with a tab. Thanks for your help. BTW, I'm a complete novice, I've never heard of SED--sorry.

EB788665,<I>Pour communiquer</I>: Explain expressions in the box,page 15. "

0E999DCD-360D-154F,Follow the suggestions on page 15 of the TE,having students choose French names and introduce themselves. "

D05R1F2C3,Model and have students repeat activities 1_6,pages 16_17, practice activities 1_5 in pairs. Alternatively,have students work in threes: two students practicing. "
 
You may try something like this:
tab=`echo "\t"`
sed "s/,/$tab/" /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top