Solved

sed and replacement

Posted on 2009-03-31
5
379 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
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:Kdo
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:
Kdo 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

815 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

11 Experts available now in Live!

Get 1:1 Help Now