Berkeley CSUA MOTD:Entry 16346
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/25 [General] UID:1000 Activity:popular
5/25    

1999/8/19-21 [Computer/SW/Unix] UID:16346 Activity:high
8/19    Shell script gurus please help.  I need to strip the first 10 lines
        and the last 3 lines off a whole bunch of files.  Is there an easy
        way to use sed to do this?  Thanks.
        \_ Sounds like a trivial job for head and tail.
           \_ It is: cat foo | tail -n +10 | tail -r | tail +4 | tail -r
           \_ Not completely trivial.  You'd need a wc in there somewhere.
              head needs a +<number> functionality.
              \_ Suppose you also have GNU tac:
                        head +10 | tac | head +3 | tac
              \_ Why the wc? head -n 10, tail -3? --dim
                 should work.  -- schoen
        \_ perl.
                \-there is a fairly evil way to do it in sed [first 10 lines
        is easy] last 3 is somewhat evil. not a good idea to do in sed unless
        like at least a 3rd level sed user. if you explain better what you
                \_ I still need 23 exp to make 3rd level.
        want i can probably five you the incantation ... do you want to SEE
        the first 10 and last 3 or do you want to delete them and write the
        file back with the first 10 gone and the bottom 3 gone. also, if you
        are operating on a bunch of files, the sed line count will continue
        across files ... so you have to operate on them one at a time.
        using tac is even more begging the question than saying "ues perl".
        using head/tail is cheeseball, just like "cut" is cheeseball [i use
        cut a lot but i at least know it is cheeseball.]. this is actually
        probably something you want to do inperl because writing the "error
        checks" [what if it is a 5 line file] is simpler in pl. --psb, 18th
        level sed mage.
        \_ sed, yucky.  awk, yucky.  perl, good.
                                        \-Don't be too proud of this
        technological terror you've compiled. The abilities of perl are
        insignificant next to the power of Emacs. --parth vader
        deathstar.lbl.gov.      43200   A       131.243.164.67
                \_ Oh yeah?  Let's see you grab the first 10 and last 3 lines
                   of a list of files in emacs from the command line.
                \_ I need the files without the first 10 lines and the
                   last 3 lines.  BTW, "head +3" doesn't work. head does
                   NOT take "+" parameters.  Thanks a lot mighty psb.
                   \_ perl.
2025/05/25 [General] UID:1000 Activity:popular
5/25    

You may also be interested in these entries...
2012/9/20-11/7 [Computer/SW/Unix, Finance/Investment] UID:54482 Activity:nil
9/20    How do I change my shell? chsh says "Cannot change ID to root."
        \_ /usr/bin/chsh does not have the SUID permission set. Without
           being set, it does not successfully change a user's shell.
           Typical newbie sys admin (on soda)
           \_ Actually, it does: -rwsr-xr-x 1 root root 37552 Feb 15  2011 /usr/bin/chsh
	...
2012/9/24-11/7 [Computer/SW/Languages, Computer/SW/Unix] UID:54484 Activity:nil
9/24    How come changing my shell using ldapmodify (chsh doesn't work) doesn't
        work either? ldapsearch and getent show the new shell but I still get
        the old shell on login.
        \_ Scratch that, it magically took my new shell now. WTF?
           \_ probably nscd(8)
	...
2012/4/27-6/4 [Computer/SW/Languages/Misc, Computer/SW/Unix] UID:54372 Activity:nil
4/27    I wrote a little shell script to collect iostat data:
        #!/bin/bash
        DATE=`date +%m%d`
        DATADIR=/var/tmp/user
        OUTPUTFILE=$DATADIR/$DATE.out
        while true
	...
2011/10/26-12/6 [Computer/SW/Unix] UID:54202 Activity:nil
10/24  What's an easy way to see if say column 3 of a file matches a list of
       expressions in a file? Basically I want to combine "grep -f <file>"
       to store the patterns and awk's $3 ~ /(AAA|BBB|CCC)/ ... I realize
       I can do this with "egrep -f " and use regexp instead of strings, but
       was wondering if there was some magic way to do this.
       \_ UNIX has no magic. Make a shell script to produce the ask or egrep
	...
2011/5/19-7/13 [Computer/SW/Languages/Misc] UID:54115 Activity:nil
5/19    If script A runs, and calls script B ..... is it possible for me to exit\
        script A based on results of script B and not continue?
        \_ assume any shell
        \_ Yes.
           \_ without passing the result to some stupid temp file?
              \_ It sounds like you want "scriptb || exit", which will run
	...
2009/8/19-9/1 [Computer/SW/Unix] UID:53285 Activity:nil
8/18    Hi again, new freebsd guy here again, in bash I was able to go
        LD_LIBRARY_PATH=/opt/foo/lib ./runmyapp
        I managed to do this in tcsh by using setenv in a shell script
        that setenv's the lib path and then executes $1, just wondering
        if there was a way to do it in 1 line from the cmd line as in bash?
        Thanks, btw %2c or %3c worked.  Freebsd, tcsh and vi forever!
	...
2009/7/22-27 [Computer/SW/Unix] UID:53181 Activity:nil
7/22    Why does everyone's 'mail last read' date say Jul 19th? even for people
        who don't log in (shell is safesorry)?  Just wondering O mighty unix
        gurus.
        \_ Modification time change when it was copied to new soda.
	...