Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sed and replacement

Posted on 2009-03-31
5
Medium Priority
?
407 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
[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
  • 3
  • 2
5 Comments
 
LVL 46

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 46

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 46

Accepted Solution

by:
Kent Olsen earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

721 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