tags:

views:

402

answers:

5

I am in directory with files consisting of many lines of lines like this:

98.684807 :(float)
52.244898 :(float)
46.439909 :(float)

and then a line that terminates:

[chuck]: cleaning up...

I am trying to eliminate :(float) from every file (but leave the number) and also remove that cleaning up... line.

I can get:

sed -ie 's/ :(float)//g' *

to work, but that creates files that keeps the old files. Removing the -e flag results in an unterminated substitute pattern error.

Same deal with:

sed -ie 's/[chuck]: cleaning up...//g' *

Thoughts? Thanks!

+1  A: 
sed -i -e 's/ :(float)//g' *
Ignacio Vazquez-Abrams
+1  A: 
sed  -i  ''  -e  's/:(float)//'  -e  '/^.chuck/d'  *

This way you are telling sed not to save a copy (null length backup extention to -i) and separately specifying the sed commands.

DigitalRoss
+2  A: 
sed -ie expression [files...]

is equivalent to:

sed -ie -e expression [files...]

and both mean apply expression to files, overwriting the files, but saving the old files with an "e" as the backup suffix.

I think you want: sed -i -e expression [files...]

Now if you're getting an error from that there must be something wrong with your expression.

profjim
A: 

your numbers are separated with (float) by the : character. Therefore, you can use awk/cut to get your numbers. Its simpler than a regex

$ head -n -1  file | awk -F":" '{print $1}'
98.684807
52.244898
46.439909

$ head -n -1  file | cut -d":" -f1
98.684807
52.244898
46.439909
ghostdog74
+1  A: 

Check to see if you have any odd filenames in the directory.

Here is one way to duplicate your error:

$ touch -- "-e s:x:"
$ ls
-e s:x:
$ sed -i "s/ :(float)//g' *
sed: -e expression #1, char 5: unterminated `s' command

One way to protect against this is to use a double dash to terminate the options to sed when you use a wild card:

$ sed -i "s/ :(float)//g' -- *

You can do the same thing to remove the file:

$ rm "-e s:x:"
rm: invalid option -- 'e'
$ rm -- "-e s:x:"
Dennis Williamson