MLUG: Re: [MLUG] Tcsh Programming (sed, awk, grep)
Re: [MLUG] Tcsh Programming (sed, awk, grep)
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
If you're just trying to delete the grepped lines from the file, would

<code>
grep -v $eatme now.file >foo
mv foo now.file
</code>

suit your needs?

"When people ask me whether open source is credible, I ask, 'Do you believe in the Internet?'" - Tim O'Reilly

On Tue, 1 Oct 2002, Davis, Ryan Wiley (UMC-Student) wrote:

> Well I have a question that has been stumping me for a while so I thought I might throw it out there. I kinda need to know soon becuase this needs to be done by tonight.
>
> So I am created a shell script to do some automated tasks. The function I am stuck on goes as thus: I take a file and parse through it with grep looking for a certain entry in the file. When that line is found I want to remove said line from the file. Example in code is here:
>
> <code>
>
> set foo = `grep $eatme now.file`
> sed -n '/^\"$foo\"/d' now.file
>
> I also tried:
> sed -n '/^\$foo\/d' now.file
> and
> sed -n '/^$foo/d' now.file
> </code>
>
> Now grep is taking that entry (from variable $eatme) and storing it in "foo", but I can't pass that variable into sed. Does anyone know how to do this or maybe a better way? I also tried to pipe the output of the grep'ed line into sed, Im sure this can probably be done but I don't know the syntax? Can you do this with awk? Supposedly the syntax I use in sed above works for deleting a string with said but the problem is the variable, it seems like it just wont pass into sed. I know that you can use grep to pull out all the entries of the file that dont contain the grep'ed line and then input them back into the file, but Id rather use sed (because thats what its for).
>
> -Ryan
>
> --
> To unsubscribe, go to http://mlug.missouri.edu/members/edit.php
>
> Archives are available at http://mlug.missouri.edu/list-archives/
>

--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php

Archives are available at http://mlug.missouri.edu/list-archives/