UNIX replace particular line in file -
i have file 5.5gb of size. want view particular line of file. lets line number 100001 , want replace line own texts. how achieve operation using unix command. can not view file in editor. can not opened , remote machine.
can share idea view line , replacing other texts?
thanks :)
if want modify line in-place , replacement data same length text being replaced, can use dd
(carefully!) overwrite part of file.
# getting byte offsets of start , length of line perl -ne '$s+=length; if ($.==100001) {print "$s + ",length,"\n"; exit}' bigfile # writing on existing data echo 'new line' | dd of=bigfile bs=1 seek=$start count=$length conv=notrunc
if replacement data different length, , it's not @ end of file, have no choice rewrite file. requires having enough disk space keep both bigfile
, copy of it!
# old file renamed bigfile.bak; new bigfile written changes. sed -i.bak -e '100001 c \ new line' bigfile
Comments
Post a Comment