Reputation: 11
Is there any way I can delete specific lines from the file?. e.g. I have 8 files that are names as Crest_001.dat, Crest_002.dat, ..., Crest_008.dat. Now I want to delete lines starting from 10 to 30000 from all these files. Right now, I am opening each file manually in vim and using following command: ":10,30000d"
This takes lot of time as my files are huge! Is there any way I can use a script to do this?
Upvotes: 1
Views: 93
Reputation: 1061
for i in $(find . -name 'Crest*.dat' -print 2>/dev/null) do sed -i '10,30000d' "$i" done
Upvotes: 0
Reputation: 4267
if your sed supports -i
, you can use sed
sed -i.bak '10,30000d' Crest_00{1..8}.dat
original files will be backed up with extension .bak
otherwise you need to use loop to run sed
on each file and redirect the output to another filename.
Upvotes: 2