Sponsored Content
Top Forums Shell Programming and Scripting Delete lines starting with these strings Post 302837539 by Little on Friday 26th of July 2013 04:05:03 AM
Old 07-26-2013
Quote:
Originally Posted by Jotne
Or with awk
Code:
awk 'NR>3' myapplication.log

@Little
This:
sed '1,3d' myapplication.log > myapp;mv myapp myapplication.log
can be replaced by this:
sed -i '1,3d' myapplication.log
-i deletes it directly in the file, no need print, move etc
thanks i didnot knew this option.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete lines starting with XX or YY or ZZ or ....

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)
Discussion started by: orno
2 Replies

2. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

3. UNIX for Dummies Questions & Answers

Delete lines with duplicate strings based on date

Hey all, a relative bash/script newbie trying solve a problem. I've got a text file with lots of lines that I've been able to clean up and format with awk/sed/cut, but now I'd like to remove the lines with duplicate usernames based on time stamp. Here's what the data looks like 2007-11-03... (3 Replies)
Discussion started by: mattv
3 Replies

4. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

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)
Discussion started by: vsachan
2 Replies

5. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

6. Shell Programming and Scripting

delete lines starting with a pattern

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)
Discussion started by: yashwantkumar
4 Replies

7. Shell Programming and Scripting

Delete multiple lines starting with a specific pattern

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)
Discussion started by: Zurd
6 Replies

8. Shell Programming and Scripting

How to delete lines starting with specific string?

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)
Discussion started by: huiyee1
2 Replies

9. Shell Programming and Scripting

Delete all lines starting with # character

Tool used : VIM editor that comes with RHEL 7.4 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... (8 Replies)
Discussion started by: John K
8 Replies

10. Shell Programming and Scripting

Delete all lines except a line starting with string

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
MooseX::Log::Log4perl(3pm)				User Contributed Perl Documentation				MooseX::Log::Log4perl(3pm)

NAME
MooseX::Log::Log4perl - A Logging Role for Moose based on Log::Log4perl SYNOPSIS
package MyApp; use Moose; with 'MooseX::Log::Log4perl'; sub something { my ($self) = @_; $self->log->debug("started bar"); ### logs with default class catergory "MyApp" ... $self->log('special')->info('bar'); ### logs with category "special" ... $self->log('.special')->info('bar'); ### logs with category "MyApp.special" $self->log('::special')->info('bar');### logs with category "MyApp.special" } DESCRIPTION
A logging role building a very lightweight wrapper to Log::Log4perl for use with your Moose classes. The initialization of the Log4perl instance must be performed prior to logging the first log message. Otherwise the default initialization will happen, probably not doing the things you expect. For compatibility the "logger" attribute can be accessed to use a common interface for application logging. Using the logger within a class is as simple as consuming a role: package MyClass; use Moose; with 'MooseX::Log::Log4perl'; sub dummy { my $self = shift; $self->log->info("Dummy log entry"); } The logger needs to be setup before using the logger, which could happen in the main application: package main; use Log::Log4perl qw(:easy); use MyClass; BEGIN { Log::Log4perl->easy_init() }; my $myclass = MyClass->new(); $myclass->log->info("In my class"); # Access the log of the object $myclass->dummy; # Will log "Dummy log entry" EVEN SIMPLER USE
For simple logging needs use MooseX::Log::Log4perl::Easy to directly add log_<level> methods to your class instance. $self->log_info("Dummy"); USING WITH MOUSE INSTEAD OF MOOSE
As this module is using Any::Moose, you can use it with Mouse instead of Moose too. This will allow to simple use it as documented above in a Mouse based application, like shown in the example below: This is your class consuming the MooseX::Log::Log4perl role. package MyCat; use Mouse; with 'MooseX::Log::Log4perl'; sub catch_it { my $self = shift; $self->log->debug("Say Miau"); } Which can be simply used in your main application then. package main; use MyCat; use Log::Log4perl qw(:easy); BEGIN { Log::Log4perl->easy_init() }; my $log = Log::Log4perl->get_logger(); $log->info("Application startup..."); MyCat->new()->catch_it(); ### Will log "Dummy dodo" ACCESSORS
logger The "logger" attribute holds the Log::Log4perl object that implements all logging methods for the defined log levels, such as "debug" or "error". As this method is defined also in other logging roles/systems like MooseX::Log::LogDispatch this can be thought of as a common logging interface. package MyApp::View::JSON; extends 'MyApp::View'; with 'MooseX:Log::Log4perl'; sub bar { $self->logger->info("Everything fine so far"); # logs a info message $self->logger->debug("Something is fishy here"); # logs a debug message } log([$category]) Basically the same as logger, but also allowing to change the log category for this log message. If the category starts with a "+", we pre- pend the current class (what would have been the category if you didn't specify one). if ($myapp->log->is_debug()) { $myapp->log->debug("Woot"); # category is class myapp } $myapp->log("TempCat")->info("Foobar"); # category TempCat $myapp->log->info("Grumble"); # category class again myapp $myapp->log(".TempCat")->info("Foobar"); # category myapp.TempCat $myapp->log("::TempCat")->info("Foobar"); # category myapp.TempCat SEE ALSO
Log::Log4perl, Moose, MooseX::LogDispatch BUGS AND LIMITATIONS
Please report any bugs or feature requests to "bug-moosex-log4perl@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. Or come bother us in "#moose" on "irc.perl.org". AUTHOR
Roland Lammel "<lammel@cpan.org>" Inspired by the work by Chris Prather "<perigrin@cpan.org>" and Ash Berlin "<ash@cpan.org>" on MooseX::LogDispatch CONTRIBUTORS
In alphabetical order: Michael Schilli "<m@perlmeister.com>" for Log::Log4perl and suggestions in the interface. Tim Bunce "<TIMB@cpan.org>" for corrections in the MooseX::Log::Log4perl::Easy module. LICENSE AND COPYRIGHT
Copyright (c) 2008-2012, Roland Lammel "<lammel@cpan.org>", http://www.quikit.at This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. perl v5.14.2 2012-06-27 MooseX::Log::Log4perl(3pm)
All times are GMT -4. The time now is 08:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy