Search for a pattern at the beginning of a line using grep

$ps -e “kworker$” error: unknown sort specifier Usage: ps [options] Try ‘ps –help ‘ or ‘ps –help ‘ for additional help text. For more details see ps(1). $ps -ef | grep “^daemon” daemon 639 1 0 May04 ? 00:00:00 /usr/sbin/atd -f $ps -ef | grep “^rtkit” rtkit 1245 1 0 May04 ? 00:00:00 /usr/lib/rtkit/rtkit-daemon $ps …

grep a file, but show several surrounding lines?

$grep -C 1 lambda doowli.py request = urllib2.Request(url) request.get_method = lambda : ‘HEAD’ try: $grep -B 1 -A 0 lambda doowli.py request = urllib2.Request(url) request.get_method = lambda : ‘HEAD’ $grep -B 1 -A 5 lambda doowli.py request = urllib2.Request(url) request.get_method = lambda : ‘HEAD’ try: response = urllib2.urlopen(request) return True except urllib2.HTTPError: return False $grep …

GREP SEARCH STRING USING BACKTICK

$ 4.2.36 7 507—> grep `whoami` algorithm.c to jeffrin@rocketmail.com $ 4.2.36 8 508—> $ 4.2.36 8 508—> whoami jeffrin $ 4.2.36 9 509—> $ 4.2.36 3 503—> grep ls ls2.wav Binary file ls2.wav matches $ 4.2.36 4 504—> grep `ls` ls2.wav grep: 12: Is a directory grep: 2008: Is a directory grep: 2010: Is a …

How does bracket expression and negation [^ ] work with grep ?

commandline session $ 4.2.20 19 519—> grep ‘[^b ]sort’ worked Heapsort Quicksort Timsort $ 4.2.20 20 520—> cat worked Bubble sort Selection sort Insertion sort Shell sort Comb sort Merge sort Heapsort Quicksort Counting sort Bucket sort Radix sort Distribution sort Timsort $ 4.2.20 21 521—>

cat + grep + wc and pipe operator

A UNIX Command $ls 1984 2001 2004 2007 2010 TED-talks-grouped-by-year-in-high-quality.metalink 1990 2002 2005 2008 2011 ted_urls 1998 2003 2006 2009 ted_download.sh $cat TED-talks-grouped-by-year-in-high-quality.metalink | grep -w url | wc -l 980 $ UNIX Explanation This command finds out the number of lines with the word “url” in the file TED*.

grep .. -m .. stop reading a file…

-m Stop reading a file after NUM matching lines. $grep -m 1 wc wcwidth.c #include $grep -m 2 wc wcwidth.c #include wchar_t cr; $grep -m 3 wc wcwidth.c #include wchar_t cr; value=wcwidth(cr); $grep -m 4 wc wcwidth.c #include wchar_t cr; value=wcwidth(cr); $grep -m 0 wc wcwidth.c $ scripts/makelst – 338 identical 19: t1=`$3 –syms $1 …

grep … matches..and that not matches..-l.. -L

$grep -r -l tcp_max * sysctl_net_ipv4.c tcp.c tcp_cong.c tcp_input.c tcp_output.c $ $grep -r -L tcp_max * af_inet.c ah4.c arp.c cipso_ipv4.c datagram.c devinet.c esp4.c fib_frontend.c fib_hash.c fib_lookup.h fib_rules.c fib_semantics.c fib_trie.c icmp.c igmp.c inet_connection_sock.c inet_diag.c inet_fragment.c inet_hashtables.c inet_lro.c inetpeer.c inet_timewait_sock.c ipcomp.c ipconfig.c ip_forward.c ip_fragment.c ip_gre.c ip_input.c ipip.c ipmr.c ip_options.c ip_output.c ip_sockglue.c Kconfig Makefile netfilter/ipt_ECN.c netfilter/nf_nat_amanda.c netfilter/nf_conntrack_l3proto_ipv4.c netfilter/nf_nat_proto_dccp.c …