The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 08:39 AM
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 10:12 AM
How to delete N bytes from the starting of the file from a C function??? jockey007 High Level Programming 2 11-15-2007 06:25 PM
Function within function (Recurance) chassis UNIX for Dummies Questions & Answers 2 09-19-2006 06:32 AM
How to convert the "select" function into a "poll" function rbolante High Level Programming 1 07-10-2001 07:49 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-16-2001
Registered User
 

Join Date: Aug 2001
Location: Malaysia
Posts: 3
Delete function

I need to delete a certain data in a file. May I know how to do it by using awk, sed any shell command?

For example, i have a file details.dat. The user will search in that file for a particular field and if match, he will delete the whole record. Do you know how to do it?

Last edited by Ohji; 08-16-2001 at 05:27 PM.
Forum Sponsor
  #2 (permalink)  
Old 08-16-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584

Can you be more specific?

  #3 (permalink)  
Old 09-21-2001
sskb
Guest
 

Posts: n/a
Arrow similar thing.....

I too have a similar requirement.
i have a text data file. in that i shall search for some words such as names. if found.. i have to delete the whole line. how can i do that using sed or awk or is there any other command that could do that.
  #4 (permalink)  
Old 09-22-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,357
sed -e /green/d <inputfile >outputfile
will make a copy of inputfile with all the lines containing "green" removed.
  #5 (permalink)  
Old 09-24-2001
sskb
Guest
 

Posts: n/a
sed : replacement of file

Thank U very much.. by the way.. is there any way to do the same without creating a new file and deleting the old file?
I mean to edit the same file with one command.
  #6 (permalink)  
Old 09-25-2001
ghoti's Avatar
Registered User
 

Join Date: Jul 2001
Location: Wales
Posts: 55
As far as I believe it should be easier to do with a script than with a single command.

And just to be akward, may I suggest that it is possible to do using grep as well....

just use:

Code:
#!/bin/bash
#Script to remove line that contains a pattern
echo "Usage: $0 PATTERNTOREMOVE INPUTFILE [OUTPUTFILE]"

if [ $# \< 2 ]; then exit; fi
#if less than two arguments, exit script

if  [ $# = 3 ] ; then
#if 3 args, then third is the output filename
        OFILE=$3;

elif [ $# = 2 ] ; then
#if 2 args then input is also output
#but a temp file is needed
        OFILE="$2"new;

else echo Too many arguments!!!;
        exit;
fi

#output all lines that DO NOT contain string to file
grep -v $1 $2 >$OFILE


if [ $# = 2 ]; then
#if only 2 args rename temp file to input filename
mv "$2"new $2;

fi
I have not tried this on many systems, so it will prob need tweaking....
-
__________________
regards,

-ghoti
  #7 (permalink)  
Old 09-25-2001
sskb
Guest
 

Posts: n/a
Smile thanks

Thanks Ghoti,
I shall try that.

by the way.. I have to do this for more files.. that I thought to use a loop.. but I forgot to use that can anybody help me?
sskb
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0