Delete a line in a file starting with - Perl one-liner


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete a line in a file starting with - Perl one-liner
# 1  
Old 01-29-2010
Delete a line in a file starting with - Perl one-liner

Hi

I need a perl onliner to delete a line in a file starting with few words.
Example

file.txt
----------
my name is don
I live in London
I am woking as engineer

I want to delete a line starting with 'I live in' using perl oneliner and in place edit with out temporary files

Thanks in advance
Ammu
# 2  
Old 01-29-2010
Code:
perl -i -nle 'print if !/I live in/' file.txt

# 3  
Old 01-31-2010
Quote:
Originally Posted by Franklin52
Code:
perl -i -nle 'print if !/I live in/' file.txt

and how about:
Code:
perl -i -nle 'print if !/^I live in\b/' file.txt

but Franklin52's solution would work well in most situations
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Checking and replacing first line in text file, one-liner?

Hello, I'm looking to check only the first line of a file to see if it is a format string, like # -*- coding: utf-8; mode: tcl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -\*- vim:fenc=utf-8:ft=tcl:et:sw=2:ts=2:sts=2if the first line is anything else, insert the above string. I'd... (3 Replies)
Discussion started by: f77hack
3 Replies

3. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

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)
Discussion started by: Tanu
3 Replies

4. Shell Programming and Scripting

Delete line - Perl one liner

Hi all, I need a Perl one liner which prints a newline into a .txt file, only where the line starts with "/mediawiki-1.19.0/". It should add the newline to the line before. My problem is, when I try to realize this (with my little knowledge :rolleyes: ) i come to the point where the // are... (4 Replies)
Discussion started by: Mr.Smith
4 Replies

5. Shell Programming and Scripting

Delete entire line starting with space

Folks, How do i delete an entire line that starts with blank space? Ex: I have a file like below. abc def (10/12) ghi _________ jkl _________ mno pqr stu (11/12) vwx I need the ouput like abc def (10/12) ghi pqr stu (11/12) vwx Thanks for your elp in advance !!!! (2 Replies)
Discussion started by: jayadanabalan
2 Replies

6. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

7. Shell Programming and Scripting

how to delete text from line starting pattern1 up to line before pattern2?

My data is xml'ish (here is an excerpt) :- <bag name="mybag1" version="1.0"/> <contents id="coins"/> <bag name="mybag2" version="1.1"/> <contents id="clothes"/> <contents id="shoes"/> <bag name="mybag3" version="1.6"/> I want to delete line containing mybag2 and its subsequent... (5 Replies)
Discussion started by: repudi8or
5 Replies

8. Shell Programming and Scripting

How to delete initial N bytes from the starting of the file using sed?

I want to delete initial N bytes of a file using sed. How can I do that? (3 Replies)
Discussion started by: jockey007
3 Replies

9. Programming

How to delete N bytes from the starting of the file from a C function???

Hi, I want to delete the initial few lines (or even bytes) from a file. I want to do this from a C function & this is in Linux platform. The truncate & ftruncate is allowing me to delete bytes from the end only. Any linux C function calls or ideas or any suggestions?? I'm in a dead... (2 Replies)
Discussion started by: jockey007
2 Replies

10. Shell Programming and Scripting

Delete the last line in a file using AWK or PERL

Is it possible to delete the last line in a file usin awk or perl? (4 Replies)
Discussion started by: suman_jakkula
4 Replies
Login or Register to Ask a Question