How do you remove selected lines from file?

How do you remove selected lines from file?

Post by Andreas Schw » Fri, 10 Mar 1995 20:20:55



|> I have a file that is created weeking that I would like to remove a
|> line that has the *text* "FILE CREATED" in it, and remove lines that
|> only contain *blanks*.

sed -e '/FILE CREATED/d' -e '/^ *$/d' < FROM > TO
--
Andreas Schwab                                      "And now for something

 
 
 

How do you remove selected lines from file?

Post by L Decka » Fri, 10 Mar 1995 05:01:32


I have a file that is created weeking that I would like to remove a
line that has the *text* "FILE CREATED" in it, and remove lines that
only contain *blanks*. I would like to incoporate this in a korn
script. What commands would accomplish this? Your help would be
appreciated. Thanks!

Example of file:

FROM:                    TO:
----                     --
   FILE CREATED              A
                             B
                             C
   A

   B
   C

 
 
 

How do you remove selected lines from file?

Post by Heiner Stev » Tue, 14 Mar 1995 00:26:00


[...]
 > I have a file that is created weeking that I would like to remove a
 > line that has the *text* "FILE CREATED" in it, and remove lines that
 > only contain *blanks*. I would like to incoporate this in a korn
 > script. What commands would accomplish this? Your help would be
 > appreciated. Thanks!
 >
 > Example of file:
 >
 > FROM:                    TO:
 > ----                     --
 >    FILE CREATED              A
 >                              B
 >                              C
 >    A
 >
 >    B
 >    C

    egrep -v '(FILE CREATED|^[  ]*$)' INPUT

Heiner

   ------------------------------------------------------

 /     World, Europe, Germany, Bavaria, Nuernberg     /
------------------------------------------------------
ZZW:q!!xx^K^DYES^MQXexit^Mquit^M^C^C^?Qq^[xxxalles kacke

 
 
 

How do you remove selected lines from file?

Post by Michael Ro » Tue, 14 Mar 1995 19:45:56



>I have a file that is created weeking that I would like to remove a
>line that has the *text* "FILE CREATED" in it, and remove lines that
>only contain *blanks*. I would like to incoporate this in a korn
>script. What commands would accomplish this? Your help would be
>appreciated. Thanks!
>Example of file:
>FROM:                    TO:
>----                     --
>   FILE CREATED              A
>                             B
>                             C
>   A
>   B
>   C

Try this:

cat file1 | grep -v "FILE CREATED" | grep -v "             " > file2

(|=pipe)
I hope, there are helpful for you
bye-bye

--
MIX-MIKE
Member of D.M.C. International
D.J. at MIKE'S DISCO Darmstadt, Germany
D.J. at FREIZEITZENTRUM Sondershausen, Germany

---------------------------------------------------------------------------

  MIKE'S DISCO * Mobildiscothek * Service *
  Ton- und Lichtanlagen * Verleih + Verkauf     DxJ/BTX: RB22 *md# / *mike#
  Ostpreussenstr. 32                          GSM-Phone: (+49) 171 321 3343
  D-64297 Darmstadt                                Tel.:   (+49) 6151 52346
                 ... i'm speaking from, not for (!) ...
  ZLS Software GmbH                                Tel.:  (+49) 6195 900500
  D-65779 Kelkheim                                 Fax :  (+49) 6195 900600
---------------------------------------------------------------------------
.

 
 
 

How do you remove selected lines from file?

Post by Lloyd Zusm » Thu, 16 Mar 1995 01:14:43




>> I have a file that is created weeking that I would like to remove a
>> line that has the *text* "FILE CREATED" in it, and remove lines that
>> only contain *blanks*. I would like to incoporate this in a korn
>> script. What commands would accomplish this? Your help would be
>> appreciated. Thanks!

>> Example of file:

>> FROM:                    TO:
>> ----                     --
>> FILE CREATED              A
>> B
>> C
>> A

>> B
>> C
> Try this:
> cat file1 | grep -v "FILE CREATED" | grep -v "             " > file2

The 'cat' command is superfluous.  This is equivalent, and it saves
a process invocation:

   grep -v "FILE CREATED" file1 | grep -v "             " > file2

--
Lloyd Zusman            01234567 <-- The world famous Indent-o-Meter.

   To get my PGP public key automatically mailed to you, please
   send me email with the following string as the subject or on a
   line by itself in the message (leave off the quotation marks):
                    "mail-request public-key"

 
 
 

How do you remove selected lines from file?

Post by Kevin Dar » Thu, 16 Mar 1995 08:36:11





>>> I have a file that is created weeking that I would like to remove a
>>> line that has the *text* "FILE CREATED" in it, and remove lines that
>>> only contain *blanks*. I would like to incoporate this in a korn
>>> script. What commands would accomplish this? Your help would be
>>> appreciated. Thanks!

>>> Example of file:

>>> FROM:                    TO:
>>> ----                     --
>>> FILE CREATED              A
>>> B
>>> C
>>> A

>>> B
>>> C

>> Try this:

>> cat file1 | grep -v "FILE CREATED" | grep -v "             " > file2

>The 'cat' command is superfluous.  This is equivalent, and it saves
>a process invocation:

>   grep -v "FILE CREATED" file1 | grep -v "             " > file2

To save yet another process invocation:

        egrep -v '(^[ ]?$)|(FILE CREATED)' file1 > file2

--------------------------------------------------------------------------------


Voice: (810) 759-7140       NeXTmail   | Chrysler Corporation
Fax:   (810) 758-8173       welcome)   | Center Line, Michigan, MIS Complex
--------------------------------------------------------------------------------

 
 
 

How do you remove selected lines from file?

Post by Zefr » Sun, 19 Mar 1995 20:41:48



>I have a file that is created weeking that I would like to remove a
>line that has the *text* "FILE CREATED" in it, and remove lines that
>only contain *blanks*.

grep -v will remove lines matching a specified pattern.  For example, to
remove lines containing the text "FILE CREATED", use:

grep -v FILE\ CREATED

in a pipe.  (Or it can take filenames as arguments.)  To remove blank lines as
well, either use two greps, or one egrep:

egrep -v \^\$\|FILE\ CREATED

-zefram

 
 
 

How do you remove selected lines from file?

Post by Pete Houst » Mon, 20 Mar 1995 23:59:36



[munch]

Quote:>in a pipe.  (Or it can take filenames as arguments.)  To remove blank lines as
>well, either use two greps, or one egrep:

>egrep -v \^\$\|FILE\ CREATED

Unless of course your "blank" lines contain whitespace in which case
you'll be needing

egrep -v ^[\ \  ]\*\$\|FILE\ CREATED
            ^ ^
            This is a space and a tab

Pete
--


 
 
 

How do you remove selected lines from file?

Post by Zefr » Wed, 22 Mar 1995 00:07:49



>you'll be needing

>egrep -v ^[\ \      ]\*\$\|FILE\ CREATED

You haven't put in enough backslashes.  Depending on your shell, you will
probably need more.  Try:

egrep -v \^\[\ \        ]\*\$\|FILE\ CREATED

-zefram

 
 
 

How do you remove selected lines from file?

Post by Pierre Gaumo » Wed, 22 Mar 1995 03:15:51




>>you'll be needing

>>egrep -v ^[\ \  ]\*\$\|FILE\ CREATED

>You haven't put in enough backslashes.  Depending on your shell, you will
>probably need more.  Try:

>egrep -v \^\[\ \    ]\*\$\|FILE\ CREATED

>-zefram

Can't you avoid all these backslashes problems by quoting the regular
expression? Try:

   egrep -v '^[         ]*$|FILE CREATED' file >out

--

Universite de Montreal.
C.P. 6128, Succursale centre-ville, Montreal,
Quebec, Canada.   H3C 3J7

 
 
 

How do you remove selected lines from file?

Post by Pete Houst » Wed, 22 Mar 1995 23:28:03





>>you'll be needing

>>egrep -v ^[\ \  ]\*\$\|FILE\ CREATED

>You haven't put in enough backslashes.  Depending on your shell, you will
>probably need more.  Try:

>egrep -v \^\[\ \    ]\*\$\|FILE\ CREATED

>-zefram

Hmm, my example works fine in bash, perhaps you are using a csh-type
shell? To be honest I would bung the whole shebang in singles, but
used backslashes to carry on the way you had it. Each to his/her own.

Pete
--


 
 
 

How do you remove selected lines from file?

Post by Zefr » Thu, 23 Mar 1995 23:20:07





>>egrep -v \^\[\ \        ]\*\$\|FILE\ CREATED

>Hmm, my example works fine in bash, perhaps you are using a csh-type
>shell?

I use zsh, with a lot of options set to make it act like sh in cases of
unmatched globbing patterns.  AFAIK, ^ isn't treated specially in bash, but [
is so it needs to be quoted if you have a file with a name such as '^ '.  Of
course, in csh it would have to be quoted anyway.

Quote:>       To be honest I would bung the whole shebang in singles, but
>used backslashes to carry on the way you had it. Each to his/her own.

Yes, if I were really doing this I would put in in SQs, but I was feeling
perverse.  :-)

-zefram

 
 
 

How do you remove selected lines from file?

Post by Stephen Friedm » Wed, 05 Apr 1995 04:00:00


] I have a file that is created weeking that I would like to remove a
] line that has the *text* "FILE CREATED" in it, and remove lines that
] only contain *blanks*. I would like to incoporate this in a korn
] script. What commands would accomplish this? Your help would be
] appreciated. Thanks!

--- Couldn't you do this with a couple of simple grep commands?

% grep -v "FILE CREATED" flie1 > file2
% grep -v "^ *$" file2 > file3

Dump these in a file w/ variables as filenames and 'source' em as
necessary. No?

----------------------------
Stephen Friedman  (otterley)

----------------------------

 
 
 

How do you remove selected lines from file?

Post by Ted M. Troccola X47 » Tue, 11 Apr 1995 04:00:00



Quote:>I have a file that is created weeking that I would like to remove a
>line that has the *text* "FILE CREATED" in it, and remove lines that
>only contain *blanks*. I would like to incoporate this in a korn
>script. What commands would accomplish this? Your help would be
>appreciated. Thanks!

Sed!

sed -e '/FILE CREATED/d' -e '/^ *$/d' YOUR_INPUT_FILE

In sed the -e is for specifying that the next argument is a command.  (It is only
necessary when you have two or more commands)

The rest looks to be straight foward!

CYA
Ted

p.s.  Your shell wont matter!  CSH, TCSH, Korn..... They should all work with this!

 
 
 

How do you remove selected lines from file?

Post by Tony Nugen » Tue, 18 Apr 1995 04:00:00




>] I have a file that is created weeking that I would like to remove a
>] line that has the *text* "FILE CREATED" in it, and remove lines that
>] only contain *blanks*. I would like to incoporate this in a korn
>] script. What commands would accomplish this? Your help would be
>] appreciated. Thanks!
>--- Couldn't you do this with a couple of simple grep commands?
>% grep -v "FILE CREATED" flie1 > file2
>% grep -v "^ *$" file2 > file3

Why the intermediate file2 and then file3 that would both need to
be deleted?

Try:

% grep -v "FILE CREATED" file1 | grep -v "^ *$" > file2
% mv file2 file1

Even better, use egrep:

% egrep -v 'FILE CREATED|^[^I ]*$' file1 > file2
% mv file2 file1

(That ^I is there to indicate a Tab character).

Quote:>Dump these in a file w/ variables as filenames and 'source' em as
>necessary. No?

Why source these commands?  It doesn't seem so necessary that the
current shell run them.  Besides, they would fit into any shell
script: korn, Bourne, or (gasp!) (t)csh!  :-)

Cheers
Tony
  Tony Nugent  Griffith University, Brisbane, Queensland, Australia
  // \\          // \\  // \\          // \\  // \\  // \\          // \\  //
 \': | \\      // | :,\\': | \\      // | :,\\': | \': | \\      // | :,\\': |
  \\ | | \\  // | | //  \\ | | \\  // | | //  \\ | |\\ | | \\  // | | //  \\ |
    \\ | :,\\': | //      \\ | :,\\': | //      \\ | \\ | :,\\': | //      \\
      \\ //  \\ //          \\ //  \\ //          \\  \\ //  \\ //          \\

 
 
 

1. select line from file, and then the next line a week later

Let's say I have a file of 5 email addresses. What if I wanted to email
one person on the list, in sequence, every friday.  So on the first
friday, I would email the first person. The following friday I would
email the second person, and so on....

Now I could cron it for friday, but how can I get the script to grab
line one the first time I run it, then grab line 2 the next time I run
it. Is this even possible?

I don't think 'case' can do this for me. I am guessing awk might be
able to, but I am no good at awk.

2. X-resulotion

3. Removing lines from text file based on line number

4. green vs. native threads

5. how to: remove last line from file 1 and append t0 file 2

6. Xwindows screen garbled with S3 Trio64 video card

7. recursively removing only selected files

8. Multicast Permissions

9. Removing funny files (Re: how do i remove a file with a ~ in it ????)

10. Can't remove a file called "---remove-files"

11. How can I prepend comments into selected lines of a data file?