473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to delete the lines from text file?

Hi

i am having an text file

test1.txt contains the following data:

Expand|Select|Wrap|Line Numbers
  1. Abcd
  2. 2222
  3. ERROR:duplicate
  4. ERROR:Getinstrument
  5. ERROR:duplicate
  6. www
  7. xxx
  8.  
here i want the output which only contain the word error

if i use the command :v/ERROR/d

then output :
Expand|Select|Wrap|Line Numbers
  1. ERROR:duplicate
  2. ERROR:Getinstrument
  3. ERROR:duplicate
  4.  
now i want the output which contains the line other than
ERROR:duplicate

output should be only ERROR:Getinstrument

can anybody help me in this, how to get the lines other than ERROR:duplicate???

Thanks,
Priyanka
Apr 13 '11 #1
2 1964
miller
1,089 Expert 1GB
Use a hash to match and skip duplicate lines:

perlfaq4 - How can I remove duplicate elements from a list or array?

- Miller
Apr 13 '11 #2
input
*************
Expand|Select|Wrap|Line Numbers
  1. /home/user> cat inputfile
  2. Abcd
  3. 2222
  4. ERROR:duplicate
  5. ERROR:Getinstrument
  6. ERROR:duplicate
  7. www
  8. xxx
  9. /home/user> 
program
*************
Expand|Select|Wrap|Line Numbers
  1. /home/user> cat > prog
  2. open(FH,"inputfile");
  3. open(FH1,">","outputfile");
  4.  
  5. while(<FH>)
  6. {
  7.  if ( $_ =~ m/ERROR/)
  8.  {
  9.    if( $_ =~ m/duplicate/)
  10.    {
  11.     ## When Error & duplicate are there in the input we are not writing it to output file
  12.    }
  13.    else
  14.    {
  15.    ##prinitng those lines which are not having error or duplicate
  16.    print FH1 $_;
  17.    }
  18.  }
  19. }
  20. close(FH);
  21. close(FH1);
running program
********
Expand|Select|Wrap|Line Numbers
  1. /home/user> perl prog
output
*******
Expand|Select|Wrap|Line Numbers
  1. /home/user> cat outputfile
  2. ERROR:Getinstrument
  3. /home/user>
hope this can work
Nov 21 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Ruben | last post by:
Hello. I am trying to read a small text file using the readline statement. I can only read the first 2 records from the file. It stops at the blank lines or at lines with only spaces. I have a...
0
by: John M. Lembo | last post by:
I am using Perl to parse a text file and output to another file. The text file has data on Unix virtual memory (vmstat) and I want to delete lines that I don't want and output lines that I want to...
2
by: Bob A | last post by:
I do a weekly import of data from two text files, using two schema files. I have automated the import process that gets the data from the two files using a macro, and everything works great. ...
2
by: Doug Oliver | last post by:
I've got an intermittent problem when trying to write to a text file (used as a log). ASPNET has modify on folder, and at times logs to file, then I get a null reference exception, followed on...
2
by: Pipex News Group | last post by:
I Have a text file that I want to delete using the On Click event of a forms button, the text file is along the following path: C:\1.txt I have managed to create the text file from Access...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
2
by: cdun2 | last post by:
Hello, I have some code that reads each line of a text file, and if a line is found where the length of the string in the line is 384, it writes the line to a text file. The other step that I...
1
by: Osoccer | last post by:
...to a different folder and in the relocated file concatenates all of the lines in one long string with a space between each line element. Here is a fuller statement of the problem: I need a...
3
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to...
13
by: jhamb | last post by:
Hi, This code is in Perl (just a trial, not tested) to parse a text file and output to another file. It is used to delete lines that are not required and output lines that the user wants, to a new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.