?
Solved

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

Posted on 2005-03-16
5
Medium Priority
?
2,847 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

762 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