Skip to content

Instantly share code, notes, and snippets.

View chenkaie's full-sized avatar
:octocat:
Build Something...

Kent Chen chenkaie

:octocat:
Build Something...
View GitHub Profile
@chenkaie
chenkaie / gist:2421678
Created April 19, 2012 15:25
Sed example
Try this, 剛好是 14 個連續數字,才會echo出東西
echo "./12M-20120419010203-aaaa-bbb-ccc.log" | sed -n "s/.*-\([0-9]\{13\}\)-.*/\1/p"
echo "./12M-20120419010203-aaaa-bbb-ccc.log" | sed -n "s/.*-\([0-9]\{14\}\)-.*/\1/p"
echo "./12M-20120419010203-aaaa-bbb-ccc.log" | sed -n "s/.*-\([0-9]\{15\}\)-.*/\1/p"
所以你可以判斷stdout吐出來的字串是否有長度不為0來判斷是否match
如下:
@chenkaie
chenkaie / fdhijack.sh
Created December 2, 2011 18:00
Redirect stdin, stdout, stderr of a daemon to /dev/pts/#
#!/bin/sh
#
# Redirect stdin, stdout, stderr of a daemon to /dev/pts/#
#
#################################################################################################################
# Ref: stdio buffering: http://www.pixelbeat.org/programming/stdio_buffering/
# Default Buffering modes:
# stdin -> is always buffered
# stderr -> is always unbuffered
# if stdout is a terminal then buffering is automatically set to line buffered, else it is set to buffered
#!/bin/bash
# Source global definitions
[ -f /etc/bashrc ] && . /etc/bashrc
[ -f /etc/profile ] && . /etc/profile
export EDITOR=vim
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
nmap - <C-w>-
nmap + <C-w>+
" Define different behavior in left/right window
if has("autocmd")
autocmd BufEnter,BufLeave *
\ if winnr() == 1 |
\ nmap < <C-w><|
\ nmap > <C-w>>|
\ else |
\ nmap < <C-w>>|