Delete lines using AWK. 
Author Message
 Delete lines using AWK.

Hello All.

I have been trying to use AWK and Sed to try removing couple lines from
a file.
There are approx 24 lines, which are repeated arbitrarily within this
file.
How can pass the searched string to AWK in order remove these lines from
the file?

I tried placing the text to be removed in a separate file then allowing
AWK to read this file and try to delete it from the actual file.

Thanks in advance.
If anyone can help.
Khalil...........................[;?)



Mon, 22 Apr 2002 03:00:00 GMT  
 Delete lines using AWK.
Try using this format for the sed.

    cat <file> | sed 's/<string to match>/d'
you also might want to try the grep with the -v option.
I hope this can help you out some.

Quote:

> Hello All.

> I have been trying to use AWK and Sed to try removing couple lines from
> a file.
> There are approx 24 lines, which are repeated arbitrarily within this
> file.
> How can pass the searched string to AWK in order remove these lines from
> the file?

> I tried placing the text to be removed in a separate file then allowing
> AWK to read this file and try to delete it from the actual file.

> Thanks in advance.
> If anyone can help.
> Khalil...........................[;?)



Mon, 22 Apr 2002 03:00:00 GMT  
 Delete lines using AWK.

Quote:

>Hello All.

>I have been trying to use AWK and Sed to try removing couple lines from
>a file.
>There are approx 24 lines, which are repeated arbitrarily within this
>file.
>How can pass the searched string to AWK in order remove these lines from
>the file?

One method:

awk '$0 ~ var {next}{print}' var="your_string_goes_here" infile

or

gawk -v var="your_string_goes_here" '$0 ~ var {next}{print}' infile

or

gawk '$0 ~ "'"your_string_goes_here"'" {next}{print}' infile

Quote:

>I tried placing the text to be removed in a separate file then allowing
>AWK to read this file and try to delete it from the actual file.

you could do this with fgrep more easily.

fgrep -v -f remove_string_file infile

man fgrep

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 22 Apr 2002 03:00:00 GMT  
 Delete lines using AWK.

Quote:

>Try using this format for the sed.

>    cat <file> | sed 's/<string to match>/d'
>you also might want to try the grep with the -v option.
>I hope this can help you out some.

If you're trying to substitute, the above won't work.

Sed uses regular expressions, and some of the characters in the
string might be special RE characters.

Also, you've got a UUOC in the above.  

If there are no special characters, then this should work:

sed -e '/string/d' infile

Chuck Demas
Needham, Mass.

Quote:


>> Hello All.

>> I have been trying to use AWK and Sed to try removing couple lines from
>> a file.
>> There are approx 24 lines, which are repeated arbitrarily within this
>> file.
>> How can pass the searched string to AWK in order remove these lines from
>> the file?

>> I tried placing the text to be removed in a separate file then allowing
>> AWK to read this file and try to delete it from the actual file.

>> Thanks in advance.
>> If anyone can help.
>> Khalil...........................[;?)

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 22 Apr 2002 03:00:00 GMT  
 Delete lines using AWK.

Quote:

> Hello All.

> I have been trying to use AWK and Sed to try removing couple lines from
> a file.
> There are approx 24 lines, which are repeated arbitrarily within this
> file.
> How can pass the searched string to AWK in order remove these lines from
> the file?

> I tried placing the text to be removed in a separate file then allowing
> AWK to read this file and try to delete it from the actual file.

> Thanks in advance.
> If anyone can help.
> Khalil...........................[;?)

An example of the file with the criteria for line removal would be
helpful ...

Have you tried looking at grep -vf ?

Just a suggestion.
Ted



Mon, 22 Apr 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. deleting records in a file using AWK, SED, or kshell

2. deleting records using AWK, SED, etc.

3. using awk to edit a single line

4. Update lines using awk

5. processing one line in a file at a time using awk

6. join a range of lines using awk/sed

7. using awk to remove header and footer lines

8. Question: How to remove END OF LINE using AWK or SED

9. find a key word and delete 5 lines before it and 5 lines after this

10. awk -- pattern match a line and the line that follows

11. Outputting info from awk and using the info to name the awk output file

12. Find and Delete Recursively with awk

 

 
Powered by phpBB® Forum Software