Solved

Regular Expression (sed editor)

Posted on 2002-07-14
2
323 Views
Last Modified: 2010-05-18
Hello !

I have following file, called for example "a.txt"

f_a
m_b

Now I want to replace each first character at a line followed by "_", by the same character followed by "@",
in other words I wish to receive following file.

f@a
m@b

It's important for me to execute the upper task using sed editor, and I do it in the following way:

>> sed s/"^(.)_"/"\0@"/ a.txt > b.txt

But for any reason this command doesn't work.

Can you please explain what is a problem.

Txs,
Alex

0
Comment
Question by:alexgor
2 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 100 total points
ID: 7152593
sed -e 's/^\(.\)_/\1@/' a.txt

problems are:
  1. usage of quotes
  2. number of matched patter is \1 not \0
0
 

Author Comment

by:alexgor
ID: 7152608
Thank you very much.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 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