grep invert search with context
If the lines are all unique you could grep the lines you want to remove into a file, and then use that file to remove the lines from the original, e.g. grep -C 2 “line I don’t want” < A.txt > B.txt grep -f B.txt A.txt
If the lines are all unique you could grep the lines you want to remove into a file, and then use that file to remove the lines from the original, e.g. grep -C 2 “line I don’t want” < A.txt > B.txt grep -f B.txt A.txt
If you are on the first line, pressing (upper case) J will join that line and the next line together, removing the newline. You can also combine this with a count, so pressing 3J will combine all 3 lines together.
There is no difference between umask 0022 and umask 022. The octal umasks are calculated via the bitwise AND of the unary complement of the argument using bitwise NOT. Set the umask like this: el@apollo:~$ umask 0077 el@apollo:~$ umask 0077 el@apollo:~$ umask 0022 el@apollo:~$ umask 0022 Brief summary of umask value meanings: umask 077 – … Read more
I found this script somewhere. I don’t remember where, but it works for me: #!/bin/ksh line=”———————————————” pids=$(/usr/bin/ps -ef | sed 1d | awk ‘{print $2}’) if [ $# -eq 0 ]; then read ans?”Enter port you would like to know pid for: ” else ans=$1 fi for f in $pids do /usr/proc/bin/pfiles $f 2>/dev/null | … Read more
Yes, you can access a gzip file randomly by reading the entire thing sequentially once and building an index. See examples/zran.c in the zlib distribution. If you are in control of creating the gzip file, then you can optimize the file for this purpose by building in random access entry points and construct the index … Read more
Directories need the execute permission set in order to see their contents. From http://content.hccfl.edu/pollock/AUnix1/FilePermissions.htm You can think of read and execute on directories this way: directories are data files that hold two pieces of information for each file within, the file’s name and it’s inode number. Read permission is needed to access the names of … Read more
Do you have the server name in a shell variable? Are you using a sh-like shell? If so, ${SERVERNAME%%.*} will do what you want.
There were some… http://www.gnu.org/s/hello/manual/libc/Error-Codes.html Portability Note: In many older Unix systems, this condition was indicated by EWOULDBLOCK, which was a distinct error code different from EAGAIN. To make your program portable, you should check for both codes and treat them the same. http://lists.parisc-linux.org/hypermail/parisc-linux/9895.html On some SysV systems EAGAIN != EWOULDBLOCK. I think we inherited the … Read more
Addressing the proposed solution from dmckee: While some versions of Bash may allow hyphens in function names, others (MacOS X) do not. I don’t see a need to use return immediately before the end of the function. I don’t see the need for all the semi-colons. I don’t see why you have path-element-by-pattern export a … Read more
A friend pointed me towards tput(1), and I cooked up this solution: #!/bin/sh # ack-wrapper – use tput to try and detect whether the terminal is # color-capable, and call ack-grep accordingly. OPTION=’–nocolor’ COLORS=$(tput colors 2> /dev/null) if [ $? = 0 ] && [ $COLORS -gt 2 ]; then OPTION=” fi exec ack-grep $OPTION … Read more