I have a file like below. It has around 300 lines like below. All the lines starting with # are comments.
For readability, I removed all lines starting with # from vi (vim editor) using the command :g/^#/d . It seemed to have worked.
But, which is more accurate/safe :g/^#/d or :g/^ *#/d and why ? This is super-important configuration file. Hence I want to use the most accurate command.
Hi There!
My final task for today is to delete lines starting with certain numbers
for e.g., my text block is
and i want to delete all lines starting with 11 or 17 or 21
I know i can use multiple sed commands like
sed '/^11,/d' <filename>
sed '/^17,/d' <filename>
sed '/^21,/d'... (2 Replies)
Hi All,
Was wondering how I can do the following....
I have a String as follows
"ACCTRL000005022RRWDKKEEDKDD...."
This string can be in a file called tail.out or in a Variable called $VAR2
Now I have another variable called $VAR1="000004785" (9 bytes long), I need the content of... (5 Replies)
Hi,
I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this:
Records
P1
10,23423432
,77:1
,234:2
P2
10,9089004
,77:1
,234:2
,87:123
,9898:2
P3
456456
P1
:123,456456546
P2
abc:324234 (2 Replies)
i have a file sample.txt containing
i want to delete lines starting with 123 neglecting spaces and tabs.
but not lines containing 123. i.e.
i want files sample.txt as
help me
thanxx (4 Replies)
Hi, just tried some script, awk, sed for the last 2 hours and now need help.
Let's say I have a huge file of 800,000 lines like this :
It's a tedious job to look through it, I'd like to remove those useless lines in it as there's a few thousands :
Or to be even more precise :
if line1 =... (6 Replies)
Sample file:
This is line one,
this is another line,
this is the PRIMARY INDEX line
l ;
This is another line
The command should find the line with “PRIMARY INDEX” and remove the last character from the line preceding it (in this case , comma) and remove the first character from the line... (5 Replies)
Platform : RHEL 5.8
I have text file called myapplication.log . In this file, I have around 800 lines which start with the followng three strings
PWRBRKER-3493
PWRBRKER-7834
SCHEDULER-ERROR
How can I delete these lines in one go ? (13 Replies)
Dear all,
I would like to delete even lines starting with "N" together with their respective titles which are actually odd lines.
Below is the example of input file. I would like to remove line 8 and 12 together with its title line, i.e., line 7 and 11, respectively.... (2 Replies)
e.g.
File name: File.txt
cat File.txt
Result:
#INBOUND_QUEUE=FAQ1
INBOUND_QUEUE=FAQ2
I want to get the value for one which is not commented out.
Thanks, (3 Replies)
Shell : bash
OS : RHEL 6.8
I have a file like below.
$ cat pattern.txt
hello
txt1
txt2
txt3
some other text
txt4
I want to remove all lines in this file except the ones starting with txt . How can I do this ? (4 Replies)
Discussion started by: omega3
4 Replies
LEARN ABOUT CENTOS
file::inplace
File::Inplace(3) User Contributed Perl Documentation File::Inplace(3)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.
POD ERRORS
Hey! The above document had some coding errors, which are explained below:
Around line 283:
You forgot a '=back' before '=head1'
Around line 285:
'=item' outside of any '=over'
perl v5.16.3 2005-01-29 File::Inplace(3)