![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 07: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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
Can you be more specific? |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
sed -e /green/d <inputfile >outputfile
will make a copy of inputfile with all the lines containing "green" removed. |
|
#5
|
|||
|
|||
|
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
|
||||
|
||||
|
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
-
__________________
regards, -ghoti |
|
#7
|
|||
|
|||
|
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 The UNIX and Linux Forums |