views:

29

answers:

1
+1  Q: 

scripts on Cshell

hello, I've got some problem, I have list of data in the file:

053-37878 03828008 Moskovitch James 500
052-34363 01234567 Mendelson Kippi 450
053-32322 03828008 Jameson Shula 350
054-39238 03333333 Merden Moshe 300

is it possible rewrite this list in the same file (without using temporary file) but without last number thanks in advance for any help (I'm talking about C-Shell scripts)

+1  A: 
  1. Why do you need to avoid temporary files?

    cut -d " " -f 1,2,3 myfile > myfile2; mv myfile2 myfile
    
  2. You can also easily use Perl's -i switch to edit the file in place. It still creates a temp file under the covers, IIRC.

  3. If you need this for homework, use Perl to read the file into memory (File::Slurp), chop off last field using regex or somesuch; and write over the file from entire stored data using another File::Slurp

DVK
This is broken and dangerous! The clobbering from the `> myfile` happens *before* `cut` can read from it, and so this will simply delete the contents of `myfile`! It's an easy mistake to make, and this is *fine* if you have `cut -d " " -f 1,2,3 my-in-file > my-out-file`.
Antal S-Z
@Antal S-Z: I need to work with the same file (no temporary files) is it possible to solve this problem?
lego69
lego69: Why? DVK is right—it's an odd requirement. And their first answer seems like the best one to me (especially since Perl is just creating a temp file too.)
Antal S-Z
its my homework, I'm trying to undrstand how can I solve this problem, but I'm stuck with this requirement!
lego69
lego69: Please tag all homework questions as such.
Antal S-Z