Solved

sed and replacement

Posted on 2009-03-31
5
389 Views
Last Modified: 2012-05-06
my input to sed is:
my_test-testing.2.txt  mytest2 mytest3 mytest4

I am piping it to sed to output the following instead (add the@ at the end of the first block):
my_test-testing.2.txt@  mytest2 mytest3 mytest4

I tried the following but it doesnt' seem to work:
sed "s/ (.*)\.\S+)\s(.*) /1@ /"
0
Comment
Question by:NewtonianB
  • 3
  • 2
5 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 24032044
Hi Newton,

Take the simple approach.  :)   Just change the first space to '@', or replace it with @space '@ '.

  sed 's/ /@/'



Kent
0
 

Author Comment

by:NewtonianB
ID: 24032206
hey, i didn't make it clear enough but the reason i was using reg exp is that there could be a space within the first block
Basically i only know its the end of the first block when theres a dot followed by some characters(letters) followed by a space
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 24032290
Ok,  :)

Try this one:

   sed "s/[^\]*\.[^ ]*/&@ /"


sed varies a bit according to distribution, but that one worked fine in RHEL.


Kent
0
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 24032336
Actually, there's a typo there.  (Not sure why it seems to work, either....)

  sed "s/[^\.]*\.[^ ]*/&@/"

This one is correct.   :)


Kent
0
 

Author Closing Comment

by:NewtonianB
ID: 31564962
very nice thanks!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

820 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