keyongtech


  keyongtech > solaris > 03/2008

 #1  
03-04-08, 11:15 AM
ABSOLUT
Hi,

I have the variable Line=adios.
If I have this file (palabras)

hola
adios
ahora

And I want to remove the line "adios" and the file will be:

hola
ahora


How could I remove the line adios?

I'm trying:

sed '/"$Line"/d' < palabras > palabras2

But doesn't work. Any help?
Thanks a lot and sorry for my english
 #2  
03-04-08, 11:43 AM
PM
ABSOLUT wrote:
[..]
> hola
> ahora
>> How could I remove the line adios?

>
> I'm trying:
>
> sed '/"$Line"/d' < palabras > palabras2
>



sed "/$Line/d" < palabras > palabras2
 #3  
03-04-08, 12:12 PM
Michael Tosch
PM wrote:
> ABSOLUT wrote:
>> sed "/$Line/d" < palabras > palabras2


or

sed '/'"$Line"'/d' palabras > palabras2

or

grep -v "$Line" palabras > palabras2
 #4  
03-04-08, 12:21 PM
Thomas Maier-Komor
PM schrieb:
> ABSOLUT wrote:
>> sed "/$Line/d" < palabras > palabras2


what if $Line happens to contain a slash character '/'?
 #5  
03-04-08, 12:23 PM
Andrew Gabriel
In article <fqjeah$8nm$1>,
Michael Tosch <eedmit> writes:
>
> or
>
> sed '/'"$Line"'/d' palabras > palabras2


The single quotes aren't necessary, e.g.

sed /"$Line"/d palabras > palabras2

This doesn't cope with certain characters in $Line, such as /

> or
>
> grep -v "$Line" palabras > palabras2


or better,

grep -vx "$Line" palabras > palabras2

to avoid partial matches.
 #6  
03-04-08, 02:11 PM
Richard Skelton
Andrew Gabriel wrote:
> In article <fqjeahnm>,
> Michael Tosch <eedmit> writes:
>
> The single quotes aren't necessary, e.g.
>
> sed /"$Line"/d palabras > palabras2
>
> This doesn't cope with certain characters in $Line, such as /
>> or better,

>
> grep -vx "$Line" palabras > palabras2
>
> to avoid partial matches.
>

I note that this is /usr/xpg4/bin/grep not /usr/bin/grep :-)

Cheers
Richard.
 #7  
03-04-08, 04:48 PM
Chris Mattern
On 2008-03-04, ABSOLUT <davidtuti> wrote:
[..]
>
> How could I remove the line adios?
>
> I'm trying:
>
> sed '/"$Line"/d' < palabras > palabras2
>
> But doesn't work. Any help?
> Thanks a lot and sorry for my english
>

Using the single quotes prevents the shell from interpolating $line.
As you don't have any special characters in the sed command, you don't
need quotes for it anywas. $line should remain quoted as it may have
spaces in it. Also, sed can take a input file name instead of using
standard input. This should work:

sed /"$Line"/d palabras > palabras2

If you want to remove all lines that contain "adios", you'd have
to set Line to that value first, of course.
 #8  
03-04-08, 06:09 PM
usenetpersongerryt
On Mar 4, 3:15 am, ABSOLUT <davidt> wrote:
>
> I have the variable Line=adios.
> If I have this file (palabras)
> hola
> adios
> ahora
> And I want to remove the line "adios" and the file will be:
> hola
> ahora
> How could I remove the line adios?


Use ed.
r FILE
/REGEX/d
w
q
<<EOF kind of construct would likely do

> I'm trying:
> sed '/"$Line"/d' < palabras > palabras2


Which would seemingly evaluate to
sed '//d'

> But doesn't work. Any help?
> Thanks a lot and sorry for my english


Nothing to do with English. You are
using single quotes and double quotes in a shell environment,
evidently inside some script. Buy a book on shell scripting maybe.
Similar Threads
How to read a text file line by line and remove some line

Can anyone please help me in writing the code in C++ : I want a read a file line by line,remove the lines which have length of a particular field in a line exceeding 63...

How to remove last line in a file

Hi, I want to know the easiest way to remove the last line in a text file, or how to catch the last line of a text file. Thanks in advance

Please help -- a ksh script to remove a line from a file (AIX)

Could someone, please, post a korn shell script example that removes an entire line from a file? Suppose I have a simple text file blah.txt containing: line 1 line 2 The...

Remove a line from a text file

Hi, I want to remove the last line in a text file. Anybody has an easy way to do so Thanks

How do I remove a line from incoming XML FILE

I have this XML FILE where I am reading data from and it has this node doctype "< ! D O C T Y P E a d f S Y S T E M " h t t p : / / w h o s c a l l i n g . c o m / d t...


All times are GMT. The time now is 12:22 AM. | Privacy Policy