Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Add a semi-colon (;) at the end of each line of text with RegEx

Posted on 2005-03-16
5
Medium Priority
?
3,286 Views
Last Modified: 2013-12-26
I am trying to add a semi-colon (;) at the end of each line of text in a file with many lines.   I want to use Regular Expressions to do it as I use UltraEdit editor (WindowsXP) which allows me to do a Search & Replace using Unix Regular Expressions.   If I use "$" it looks like it affects the carriage return (it puts a block instead of a ";" on every other line and a ";" at the beginning & end of every other line).

If I use ".$", it picks the last character instead of putting it at the end of the line (I would expect this).

How can I put a semi-colon at the end of each line?  Thank you for your help!
0
Comment
Question by:psmithphil
  • 2
  • 2
5 Comments
 
LVL 21

Accepted Solution

by:
tfewster earned 1000 total points
ID: 13560367
Try
sed "s/\(.*\)/\1;/"
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 1000 total points
ID: 13560691
or simply

s/$/;/

0
 

Author Comment

by:psmithphil
ID: 13560934
Thank you for your efforts, but I can't get what you offered to work.

I would prefer to use utilities like "sed", etc.   The files I want to manipulate are in WindowsXP.  I've tried using the GNU Utilities for Windows, but they are unreliable (I can't get the "$" to work consistently).  And I don't want to use an emulator like Cgywin.

What I am therefore trying to use is the text editor UltraEdit. It allows me to use Unix Regular Expressions, but it has both search and replace boxes (like Microsoft Word), so I can't use things like "sed".  What I'm trying to do is find how I can get to the end of the line to add the semi-colon.  If I can't do it here, is there another way to do it?
0
 

Author Comment

by:psmithphil
ID: 13561114
Well, I got it to work.  UltraEdit is a little different.

In the Find box I put  (.+)$
In the Replace box I put  \1;

That put a semi-colon at the end of each line.  Sweet!

You two are the only ones who attempted to assist me and I appreciate it!   I am splitting the points between you.  Thank you!
0
 
LVL 48

Expert Comment

by:Tintin
ID: 13561202
Regexes implementations vary a bit, so what might work for one language/platform may not work for another.

I must admit, I'm not sure why you are reluctant to run cygwin, if you are happy to install GNU Utilities for Windows.

I find cygwin is such a valuable tool on all my Windows boxes.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Loops Section Overview
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question