Unix‎ > ‎

sed awk find misc

$ find ../trunk3 -name "ccccc" | xargs stat -c "%y %s %n"

Grep binary file
$ grep -an

grep regex
grep -o "#({.*})"
grep -o "\"remainingAttempts\":.\{0,3\}"

awk < file '{ print $2 }'

create a group and replace by the group
sed "s/#(\({.*}\))/\1/"

sed, clear blank spaces
cat out2 | sed ‘s/\(\s\)*g’ > out3

sed, change word in file
sed -i ‘s/9000/9001/’ Gruntfile.js
sed -i ‘s/9000/9001/g’ Gruntfile.js (global change)

extract the first line of a file, say named somefile.txt.
sed -n 1p somefile.txt

delete all but the first line.
sed ‘1!d’ somefile.txt

to extract a range of lines, say lines 2 to 4, you can execute either of the following:
sed -n 2,4p somefile.txt sed ‘2,4!d’ somefile.txt

lines 1 to 2, and line 4
sed -n -e 1,2p -e 4p somefile.txt

reset all files
ls | xargs truncate --size 0

grep and awk
ps auxww | grep java | awk '{print $2} '

var output = $()

redirect stdin and stdout
cmd >>file.txt 2>&1

find . -printf "%T@ %Tc %p\n" | sort -n