I am trying to edit few lines in a file, but it is a very big file more than 2GB text file. Opening, editing and saving in vi editor takes a long time.1. To search and replace a string 'STRING' in a big file.2. To find few lines having string 'GROUPS' and remove them from the original file.I tried 'grep -v 'GROUPS' file > newfile', is there any better way than this.Is this possible to do without opening a file through other ways not in Vi editor.
Perl Solutionperl -e 's/gopher/World Wide Web/gi' -p -i.bak *.htmlThis command, issued at the Unix prompt, executes the short Perl program specified in single quotes. This program consists of one Perl operation: it substitutes for original word "gopher" the phrase "World Wide Web" (globally, ignoring case). The command line options imply that the Perl program should run for each file ending in
.htmlin the current directory. If any fileblah.htmlneeds changing, a backup of the original is made as fileblah.html.bak.�
For more info on perl, please go through
http://www.cs.tut.fi/~jkorpela/perl/course.html#whatis
sed solution:
for deleting GROUPS from all lines
use this :
sed -i '/GROUPS/d' file_name
OR
sed 's/old_string/new_string/g' oldfilename > newfilename
Source: VLSICore Members
0 comments:
Post a Comment