Solved

How can I use shell script to remove specific records from a flat file?

Posted on 2008-06-22
3
232 Views
Last Modified: 2008-06-24
Hi all,
Working on a little shell script to remove specific records from a flat file. I have scanned a one or two script books and googled for answers but have no success. Can someone show me how I can do this. For example, how can I remove the something like the following records from among 200 other records:
DB2ADMIN.EPISODE_1;
DB2ADMIN.EPISODE_2;
DB2ADMIN.EPISODE_3;
DB2ADMIN.EPISODE_4;
DB2ADMIN.EPISODE_5;
DB2ADMIN.EPISODE_6;
DB2ADMIN.EPISODE_7;

You see, they are not duplicates, so uniq will not do the job. Is there another keyword that can remove something lke these given a string such as '  DB2ADMIN.EPISODE_%' in a shell script?
I'll truly appreciate any help I can get on this...

Thanks
0
Comment
Question by:Enuda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 84 total points
ID: 21840132

egrep -v "DB2ADMIN.EPISODE_?" file >newfile

Open in new window

0
 
LVL 14

Assisted Solution

by:agriesser
agriesser earned 83 total points
ID: 21840890
I usually use perl for such things as the default shell utils are not able to replace contents of files without writing new ones as shown in the example from Tintin.

The perl one-liner for this would be:
perl -p -i -e 's/^DB2ADMIN\.EPISODE_[0-9]+;\n$//' yourfile

Open in new window

0
 
LVL 45

Assisted Solution

by:Kent Olsen
Kent Olsen earned 83 total points
ID: 21849804
And the sed equivalent would be:

  sed '/DB2ADMIN.EPISODE_/d' yourfile > newfile

or, if 'EPISODE_' must be followed by a digit:

  sed '/DB2ADMIN.EPISODE_[0-9]/d' yourfile > newfile


Lots of ways to do things in unix.   :)

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question