Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-22
3
Medium Priority
?
233 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 336 total points
ID: 21840132

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

Open in new window

0
 
LVL 14

Assisted Solution

by:agriesser
agriesser earned 332 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 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 332 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

688 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