How to use sed command to delete rows without backup file?

I have a large 130GB file.

# ls -lrth
-rw-------. 1 root root 129G Apr 20 04:25 syslog.log

So I need to reduce the file size by deleting the line that starts with “Nov 2”. So I gave the following command:

sed -i '/Nov  2/d' syslog.log

Therefore, I cannot edit the file using the VIM editor.

When I run the SED command, this also creates a backup file. But I have little space at the root. Try providing an alternative solution to remove a specific line from this file without increasing the server space.

+4
source share
1 answer

. sed - . -i sed, (), , .

( , , .)

- , . , sed . .

, , .

, :

seq 0 999999 > x

, , , 4:

grep -v 4 1<>x <x

STDOUT (1) STDIN. grep , 4 ( -v).

.

, , :


999991
999992
999993
999995
999996
999997
999998
999999
537824
537825
537826
537827
537828
537829

Unix truncate, . , ( wc):

( x .)

(grep -v 4 <x | tee /dev/stderr 1<>x) |& wc -c

, , , 3653658. truncate:

truncate -s 3653658 x

.

script, i. . , :

length=$((grep -v 4 <x | tee /dev/stderr 1<>x) |& wc -c)
truncate -s "$length" x

, > 2 > 4 ; (32 ?) , . ( > 4 , ), :)

, :

  • , .
  • , ( , ..) undefined. ; , .
  • , , , , , , ( ).
+5

All Articles