Solved

sed and replacement

Posted on 2009-03-31
5
351 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:Kdo
Comment Utility
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
Comment Utility
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:Kdo
Comment Utility
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:
Kdo earned 500 total points
Comment Utility
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
Comment Utility
very nice thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now