Jump to content

Truncate a file: Difference between revisions

m
Line 715:
 
# 4. trunc(): trunc file size # truncate at length
-bash-4.2$ trunc() { IFS= read -N $2 b<"$1"; echo -n "$b">"$1"; }
-bash-4.2$ echo "abcdef">bad; ls -l bad; cat bad; trunc bad 3; ls -l bad; cat bad; echo "_EOF_"
+ echo abcdef
Line 731:
_EOF_
</lang>
# NOTE: Designed for regular text files. Does not work when files contain: chars 0x00 and 0xFF as of bash 4.2 - these chars are treated differently in read -N. For this reason use of method#4 is not prefer over dd(1) or truncate(1) when using binary files, or large files.
 
=={{header|ZX Spectrum Basic}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.