version info :
vi availabe with RHEL 5.4
I have a text file with 10,000 lines. I want to copy lines from 5000th line to 7000th and redirect to a file. Any idea how I can do this?
Note:
The above scenario is just an example. In my actual requirement, the file has 14 million lines and I want to copy 2000 lines after the 12th million line
BTW.I've just realised that the vi editor we use in RHEL is actually VIM
...
If you have your file open in Vim, and you want to copy lines from 5000 to 7000 both inclusive to a new file, then use the following editor command:
Hello everybody,
My question is: how to add /tmp/work at the end of line in vi editor.
my file looks like:
cp file1
cp file2
cp file3
****
I need to add " /tmp/work" at the end of each line.
I tried this
:%s/$/" /tmp/work"
and this
:%s/$/\ /tmp/work\/
but it does not work. (2 Replies)
Hi,
how can I add at the begining and at the end of all of the lines of my text file in VI editor ? Many thanks before.
for exemple if in my file i have
line 1
line 2
I want to have :
start line 1 end
start line 2 end (3 Replies)
I am new in hp ux and I want work with vi editor, but in hp ux vi editor the backspaes and del keys doesn't work.
how can I enable them.
thanks (3 Replies)
Hi,
I knw its a silly question, but am a newbie to 'vi' editor. I'm forced to use this, hence kindly help me with this question.
How can i paste a chunk 'copied from' a different editor(gedit) in 'vi editor'?
As i see, p & P options does work only within 'vi'. (10 Replies)
Hi All,
I am running a script , working very fine on cmd prompt. The problem is that when I open do crontab -e even after setting editor to vi by
set EDITOR=vi it does not open a vi editor , rather it do as below.....
/////////////////////////////////////////////////////
$ set... (6 Replies)
Hello All,
Need one Help for one issue.
I am using a French Keyboard, so @ sign is on key 0 and i have to use right Alt + 0 to print it.
It is working everywhere but not inside Vi editor. I can type @ in shell, in notepad. But inside Vi editor it is not working, another problem is that if... (2 Replies)
I was looking through the topics and I wasn't sure if this was the best place to post this question:
I was wondering, out of curiosity, which software everyone was using to code their scripts in. I do mostly sh/ksh and my favorite has always been EditPlus because it is small, fast, yet powerful.... (409 Replies)
Discussion started by: yongho
409 Replies
LEARN ABOUT DEBIAN
file::inplace
File::Inplace(3pm) User Contributed Perl Documentation File::Inplace(3pm)NAME
File::Inplace - Perl module for in-place editing of files
SYNOPSIS
use File::Inplace;
my $editor = new File::Inplace(file => "file.txt");
while (my ($line) = $editor->next_line) {
$editor->replace_line(reverse $line);
}
$editor->commit;
DESCRIPTION
File::Inplace is a perl module intended to ease the common task of editing a file in-place. Inspired by variations of perl's -i option,
this module is intended for somewhat more structured and reusable editing than command line perl typically allows. File::Inplace endeavors
to guarantee file integrity; that is, either all of the changes made will be saved to the file, or none will. It also offers functionality
such as backup creation, automatic field splitting per-line, automatic chomping/unchomping, and aborting edits partially through without
affecting the original file.
CONSTRUCTOR
File::Inplace offers one constructor that accepts a number of parameters, one of which is required.
File::Inplace->new(file => "filename", ...)
file
The one required parameter. This is the name of the file to edit.
suffix
The suffix for backup files. If not specified, no backups are made.
chomp
If set to zero, then automatic chomping will not be performed. Newlines (actually, the contents of $/) will remain in strings
returned from "next_line". Additionally, the contents of $/ will not be appended when replacing lines.
regex
If specified, then each line will be split by this parameter when using "next_line_split" method. If unspecified, then this
defaults to s+.
separator
The default character used to join each line when replace_line is invoked with a list instead of a single value. Defaults to a
single space.
INSTANCE METHODS
$editor->next_line ()
In scalar context, it returns the next line of the input file, or undef if there is no line. In an array context, it returns a single
value of the line, or an empty list if there is no line.
$editor->replace_line (value)
Replaces the current line in the output file with the specified value. If passed a list, then each valie is joined by the "separator"
specified at construction time.
$editor->next_line_split ()
Line "next_line", except splits based on the "regex" specified in the constructor.
$editor->has_lines ()
Returns true if the file contains any further lines.
$editor->all_lines ()
Returns an array of all lines in the file being edited.
$editor->replace_all_lines (@lines)
Replaces all remaining lines in the file with the specified @lines.
$editor->commit ()
Completes the edit operation and saves the changes to the edited file.
$editor->rollback ()
Aborts the edit process.
$editor->commit_to_backup ()
Saves edits to the backup file instead of the original file.
AUTHOR
Chip Turner, <chipt@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2005 by Chip Turner
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or,
at your option, any later version of Perl 5 you may have available.
perl v5.14.2 2012-03-06 File::Inplace(3pm)