Solved

sed and replacement

Posted on 2009-03-31
5
400 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

634 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