find . -type f -print0 | xargs -0 grep -lZ "happy" | xargs -0 sed -i 's/happy/blammo/g'The -l option to grep prints file names only and stops with the first match (so no duplicates). -Z uses null byte for separator instead of newline.
Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
Monday, December 5, 2011
string find and replace in files
The -i option to sed does in place file editing, however it "modifies" each file it touches whether it actually does any replacing or not (so the file mod time is updated). By filtering through grep first, we can be sure we are only messing with files we actually want to. Replace "happy" with "blammo":
Saturday, November 12, 2011
recursive file list sorted by mod time
I end up bouncing from one project to another pretty often, and I don't like saving my workspace in my editor so that I can start with a nice, clean, blank slate. But it's nice to know what exactly I've been working on recently, so..
find . -type f | xargs ls -l 2>/dev/null | sort -r -k6,6 -k7,7 | most
Friday, November 4, 2011
hexdump
Quick little one liner for hexdump with some nice, versatile output. 1 byte per line, with
byte #[space]octal value[space]decimal value[space]hex value[space]default character set
byte #[space]octal value[space]decimal value[space]hex value[space]default character set
hexdump -v -e '"%07_ad" 1/1 " %03o"' -e '1/1 " %03u"' -e '1/1 " %03x"' -e '1/1 " %_c \n"'And in a bash script taking a file:
#!/bin/bash hexdump -v -e '"%07_ad" 1/1 " %03o"' -e '1/1 " %03u"' -e '1/1 " %03x"' -e '1/1 " %_c \n"' $1Example output when called on itself:
0000000 043 035 023 # 0000001 041 033 021 ! 0000002 057 047 02f / 0000003 142 098 062 b 0000004 151 105 069 i 0000005 156 110 06e n 0000006 057 047 02f / 0000007 142 098 062 b 0000008 141 097 061 a 0000009 163 115 073 s 0000010 150 104 068 h 0000011 012 010 00a \n 0000012 012 010 00a \n 0000013 150 104 068 h 0000014 145 101 065 e 0000015 170 120 078 x 0000016 144 100 064 d 0000017 165 117 075 u 0000018 155 109 06d m 0000019 160 112 070 p 0000020 040 032 020 0000021 055 045 02d - 0000022 166 118 076 v 0000023 040 032 020 0000024 055 045 02d - 0000025 145 101 065 e 0000026 040 032 020 0000027 047 039 027 ' 0000028 042 034 022 " 0000045 063 051 033 3 0000046 157 111 06f o 0000047 042 034 022 " 0000048 047 039 027 ' 0000049 040 032 020 0000050 055 045 02d - 0000051 145 101 065 e 0000052 040 032 020 0000053 047 039 027 ' 0000054 061 049 031 1 0000055 057 047 02f / 0000056 061 049 031 1 0000057 040 032 020 0000058 042 034 022 " 0000059 040 032 020 0000060 045 037 025 % 0000061 060 048 030 0 0000062 063 051 033 3 0000063 165 117 075 u 0000064 042 034 022 " 0000065 047 039 027 ' 0000066 040 032 020 0000067 055 045 02d - 0000068 145 101 065 e 0000069 040 032 020 0000070 047 039 027 ' 0000071 061 049 031 1 0000072 057 047 02f / 0000073 061 049 031 1 0000074 040 032 020 0000075 042 034 022 " 0000076 040 032 020 0000077 045 037 025 % 0000078 060 048 030 0 0000079 063 051 033 3 0000080 170 120 078 x 0000081 042 034 022 " 0000082 047 039 027 ' 0000083 040 032 020 0000084 055 045 02d - 0000085 145 101 065 e 0000086 040 032 020 0000087 047 039 027 ' 0000088 061 049 031 1 0000089 057 047 02f / 0000090 061 049 031 1 0000091 040 032 020 0000092 042 034 022 " 0000093 040 032 020 0000094 045 037 025 % 0000095 137 095 05f _ 0000096 143 099 063 c 0000097 040 032 020 0000098 134 092 05c \ 0000099 156 110 06e n 0000100 042 034 022 " 0000101 047 039 027 ' 0000102 040 032 020 0000103 044 036 024 $ 0000104 061 049 031 1 0000105 012 010 00a \n
Tuesday, September 27, 2011
setting up proxy pass
Make sure you load all the right modules, eg
http://www.webmasterworld.com/forum92/1727.htm
If you are getting a bunch of Error: proxy: ap_get_scoreboard_lb errors, you may need to stop and start apache (instead of reloading/restarting) (http://old.nabble.com/Error%3A-proxy%3A-ap_get_scoreboard_lb%2890%29-failed-in-child-td12128044.html)
Another error I got: client denied by server configuration: proxy:http://example.com
debian/ubuntu "Deny from all" by default in mods-available/proxy.conf, comment that out (http://artur.hefczyc.net/node/10)
http://www.webmasterworld.com/forum92/1727.htm
If you are getting a bunch of Error: proxy: ap_get_scoreboard_lb errors, you may need to stop and start apache (instead of reloading/restarting) (http://old.nabble.com/Error%3A-proxy%3A-ap_get_scoreboard_lb%2890%29-failed-in-child-td12128044.html)
Another error I got: client denied by server configuration: proxy:http://example.com
debian/ubuntu "Deny from all" by default in mods-available/proxy.conf, comment that out (http://artur.hefczyc.net/node/10)
Subscribe to:
Posts (Atom)