|
|
||||||
|
#1
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
PM wrote:
> ABSOLUT wrote: >> sed "/$Line/d" < palabras > palabras2 or sed '/'"$Line"'/d' palabras > palabras2 or grep -v "$Line" palabras > palabras2 |
|
#4
|
|
|
|
|
PM schrieb:
> ABSOLUT wrote: >> sed "/$Line/d" < palabras > palabras2 what if $Line happens to contain a slash character '/'? |
|
#5
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|