wanted: script to delete first line in files

wanted: script to delete first line in files

Post by Murray Bart » Sat, 07 Oct 1995 04:00:00



G'Day all,
I need a script to delete the first line (only) of a bunch a files.  The
first line is blank all the other lines in the file start with a
whitespace and an asterix " *".  

Thanks for your help
Regards
Murray
--
Murray Barton             | When a man despoils a work of art we call him
Perth, Western Australia  | a vandal; when he despoils a work of nature

 
 
 

wanted: script to delete first line in files

Post by Soren Dayt » Mon, 09 Oct 1995 04:00:00




>  > I need a script to delete the first line (only) of a bunch a
>  > files.  The  first line is blank all the other lines in the file
>  > start with a  whitespace and an asterix " *".
>    # rmfirst - remove first line
>    for File
>    do
>        tail +2 "$File" > tmp$$ && mv tmp$$ "$File"
>    done

        Syntax I have never  seen before.  In fact, I do not think it is valid.
        This is how I would write it:

        for file in $files
        do
                echo "1d
w" | ed -s $file
        done

soren

 
 
 

wanted: script to delete first line in files

Post by Heiner Stev » Mon, 09 Oct 1995 04:00:00


 > I need a script to delete the first line (only) of a bunch a
 > files.  The  first line is blank all the other lines in the file
 > start with a  whitespace and an asterix " *".

If you have the "tail" command:

        # rmfirst - remove first line
        for File
        do
            tail +2 "$File" > tmp$$ && mv tmp$$ "$File"
        done

If you prefer "sed":

        # rmfirst - remove first line
        for File
        do
            sed 1d "$File" > tmp$$ && mv tmp$$ "$File"
        done

Heiner
--
   ------------------------------------------------------------------


------------------------------------------------------------------
:q!ZZ^X^Cquit^Mexit^J^D^Cbye^Mlogout^M^?^\xxxxalles kacke

 
 
 

wanted: script to delete first line in files

Post by Brian S Hile » Sat, 21 Oct 1995 04:00:00





:  > >
:  > >  > I need a script to delete the first line (only) of a bunch a
:  > >  > files.  The  first line is blank all the other lines in the file
:  > >  > start with a  whitespace and an asterix " *".
[cut]

# to pass file to stdout: (in csh: quote "!")
sed -n 1!p filename >filename2

# to change file permanently:
ex -c '1d|w|q' filename

 
 
 

wanted: script to delete first line in files

Post by Jon LaBad » Thu, 02 Nov 1995 04:00:00







|> >


|> >:  > >
|> >:  > >  > I need a script to delete the first line (only) of a bunch a
|> >:  > >  > files.

        for file
        do
                ed - $file <<-!
                        1d
                        w
                        q
                !
        done

jon

 
 
 

wanted: script to delete first line in files

Post by Stan Ryckm » Thu, 02 Nov 1995 04:00:00



:
:       for file
:       do
:               ed - $file <<-!
:                       1d
:                       w
:                       q
:               !
:       done
:
:jon

Less cryptic and shorter:

        for file
        do
                awk 'NR>1' $file
        done

Stan.
--
HELP!  I'M BEING HELD PRISONER IN A .SIGNATURE FACTORY!

 
 
 

wanted: script to delete first line in files

Post by Jeremy Mathe » Fri, 03 Nov 1995 04:00:00






>:
>:   for file
>:   do
>:           ed - $file <<-!
>:                   1d
>:                   w
>:                   q
>:           !
>:   done

Good, but not quite there, Jon.

Quote:>Less cryptic, shorter and no good:

>    for file
>    do
>            awk 'NR>1' $file
>    done

Somehow, I don't think the goal of the exercise is to display all that
text on the screen.  You get to stay behind and clean the erasers.

The best solution is (in csh, since you are going to just do this from
the command line - no reason to write a script for it - and of course,
anyone with any self-respect is running tcsh [that's not flame bait at
all, is it?]) :

% foreach i (...)
foreach? ex '+1d|x' $i
foreach? end

There.  Any *more* questions?

************************************************************************
Smiley captioned version available for the humor-impaired.
Email for price and availability ;-)


          hundreds, if not thousands, of dollars, every time he posts -
************************************************************************
rwvpf wpnrrj ibf ijrfer

 
 
 

wanted: script to delete first line in files

Post by Stan Ryckm » Fri, 03 Nov 1995 04:00:00





:>:
:>:  for file
:>:  do
:>:          ed - $file <<-!
:>:                  1d
:>:                  w
:>:                  q
:>:          !
:>:  done
:
:Good, but not quite there, Jon.
:
:>Less cryptic, shorter and no good:
                        ^^^^^^^^^^^
Please don't alter text I wrote and then leave it attributed to me.
This is, at best, rude.  I think you could have made your point without
resorting to forged attributions.
:>
:>   for file
:>   do
:>           awk 'NR>1' $file
:>   done
:
:Somehow, I don't think the goal of the exercise is to display all that
:text on the screen.  You get to stay behind and clean the erasers.

Well, as Jon pointed out to me in email, his rewrites the file
whereas mine requires a (trivial) mod to write to a temp file and
mv it back.

If you will permit me:
        for file
        do
                awk 'NR>1' $file > /tmp/tmp.$$
                mv /tmp/tmp.$$ $file
        done

Happy now?

Also, this will likely be more reliable after a system crash during
its execution, although I know systems don't crash any more these
days :-).

:The best solution is (in csh, since you are going to just do this from
:the command line - no reason to write a script for it

This I disagree with.  There might be something continually running
in the background where one wants to keep the "last 10" of something
in a file (for example).  It seems to me that this is the most
probable reason for wanting to do such a thing (but we can only guess
what the original poster's reasons were).

:- and of course,
:anyone with any self-respect is running tcsh [that's not flame bait at
:all, is it?]) :

I prefer tcsh interactively (because of "dirs -v", "=0" thru "=9",
and the ability to have *both* ^H and DEL as "erase" keys).  So if they
flame, I'll defend you :-)

Cheers,
Stan.
--
HELP!  I'M BEING HELD PRISONER IN A .SIGNATURE FACTORY!

 
 
 

wanted: script to delete first line in files

Post by Dave Bro » Sat, 04 Nov 1995 04:00:00





: :
: :     for file
: :     do
: :             ed - $file <<-!
: :                     1d
: :                     w
: :                     q
: :             !
: :     done
: :
: :jon
:
: Less cryptic and shorter:
:
:       for file
:       do
:               awk 'NR>1' $file
:       done

Doesn't replace the file, just spews the edited version to stdout.
The first example using ed does what the original poster wanted
(deleting the first line from a bunch of files)

--Dave

 
 
 

wanted: script to delete first line in files

Post by Dave Bro » Sat, 04 Nov 1995 04:00:00





: :- and of course,
: :anyone with any self-respect is running tcsh [that's not flame bait at
: :all, is it?]) :
:
: I prefer tcsh interactively (because of "dirs -v", "=0" thru "=9",
: and the ability to have *both* ^H and DEL as "erase" keys).  So if they
: flame, I'll defend you :-)

I prefer zsh or bash actually.

C shell weenies would probably like zsh.  Quite a bit smaller than tcsh,
noticeably faster, and it supports both csh weenie type commands and
proper Bourne shell type commands.

So there. ( :PPP while we're all acting like a bunch of five-year-olds. :-) )

Oh, yeah.  Since this seems to be an important feature for you, zsh
allows both ^H and RUBOUT as "erase" keys.

--Dave

 
 
 

wanted: script to delete first line in files

Post by Ray A. Jon » Sun, 05 Nov 1995 04:00:00






: >:
: >: for file
: >: do
: >:         ed - $file <<-!
: >:                 1d
: >:                 w
: >:                 q
: >:         !
: >: done

: Good, but not quite there, Jon.

: >Less cryptic, shorter and no good:
: >
: >  for file
: >  do
: >          awk 'NR>1' $file
: >  done

: Somehow, I don't think the goal of the exercise is to display all that
: text on the screen.  You get to stay behind and clean the erasers.

: The best solution is (in csh, since you are going to just do this from
: the command line - no reason to write a script for it - and of course,
: anyone with any self-respect is running tcsh [that's not flame bait at
: all, is it?]) :

: % foreach i (...)
: foreach? ex '+1d|x' $i
: foreach? end

: There.  Any *more* questions?

Yeh, can't you do this without an editor?
(in bourne)
for i in filea fileb ..... filex
do
tail +2 $i > $i.new
done

That way you can check to be sure you didn't blow away your original files
if you made a typo.  I hate going to backup tapes because of typos.
: ************************************************************************
: Smiley captioned version available for the humor-impaired.
: Email for price and availability ;-)


:         hundreds, if not thousands, of dollars, every time he posts -
: ************************************************************************
: rwvpf wpnrrj ibf ijrfer

--

URL: http://www.celestial.com         One Mercer Plaza, Suite S100
                                      Mercer Island, WA 98040; (206) 236-1676
Manufacturer of InterRack (Internet-in-a-Rack), a full turn-key
system, including all the hardware, software, installation, setup, training
and support for businesses and Internet Service Providers

 
 
 

wanted: script to delete first line in files

Post by Zefr » Mon, 06 Nov 1995 04:00:00



>    for file
>    do
>            awk 'NR>1' $file
>    done

sed 1d

-zefram

 
 
 

1. script to delete first line of files

G'Day all,
I need a script to delete the first line (only) of a bunch a files.  The
first line is blank all the other lines in the file start with a
whitespace and an asterix " *".  

Thanks for your help
Regards
Murray

--
Murray Barton             | When a man despoils a work of art we call him
Perth, Western Australia  | a vandal; when he despoils a work of nature

2. Unix printing in C

3. Delete the first line of a 1.4 million lines file

4. best way to handle signals while in a blocking system call?

5. Find a string, delete that line, delete 1 line before it and all lines after it...

6. Any Ideas for SLIP and DIP problems?

7. Deleting multplie lines after matching a regex in the first line

8. multiple interface/links routing

9. Delete first and last lines of file

10. sed - delete first line of text file

11. Deleting First 10 Lines of a file

12. delete the first line in a file via bash

13. How may i do to delete a line in a file on one step ?