Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does sed leave many files around?

Tags:

linux

sed

I noticed many files in my directory, called "sedAbCdEf" or such.

  • Why does it create these files?
  • Do these have any value after a script has run?
  • Can I send these files to another location , e.g. /tmp/?

Update:

I checked the scripts until I found one which makes the files. Here is some sample code:

#!/bin/bash
a=1
b=`wc -l < ./file1.txt`
while [ $a -le $b ]; do
    for i in `sed -n "$a"p ./file1.txt`; do
        for j in `sed -n "$a"p ./file2.txt`; do
            sed -i "s/$i/\nZZ$jZZ\n/g" ./file3.txt
            c=`grep -c $j file3.txt`
            if [ "$c" -ge 1 ]
            then
                echo $j >> file4.txt
                echo "Replaced "$i" with "$j" "$c" times ("$a"/"$b")."
            fi
                echo $i" not found ("$a"/"$b")."
            a=`expr $a + 1`
        done
    done
done
like image 368
Village Avatar asked Mar 23 '12 02:03

Village


1 Answers

  • Why does it create these files?

sed -i "s/$i/\nZZ$jZZ\n/g" ./file3.txt

the -i option makes sed stores the stdout output into a temporary file.
After sed is done, it will rename this temp file to replace your original file3.txt.
If something is wrong when sed is running, these sedAbCdE temp files will be left there.

  • Do these have any value after a script has run?

Your old file is untouched. Usually no.

  • Can I send these files to another location , e.g. /tmp/?

Yes you can, see above.

Edit: see this for further reading.

like image 122
cctan Avatar answered Sep 29 '22 23:09

cctan