Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Unix</strong> Tools<br />
4. UNIX TOOLS<br />
Tools of <strong>the</strong> Trade<br />
cut – cut out various fields<br />
cut -cchars file<br />
cut -c5- data<br />
cut –c1, 10-20 data<br />
e.g. who | cut –c1-8 | sort<br />
cut -ddelimiter -ffields file<br />
cut -d: -f1 /etc/passwd<br />
paste – paste lines toge<strong>the</strong>r <strong>with</strong> tabs<br />
paste files<br />
paste -d: names addresses numbers<br />
paste -s names<br />
sed<br />
sed command file<br />
sed 's/<strong>Unix</strong>/UNIX/g' intro > temp<br />
sed -n '1,2p' intro # print first 2 lines only<br />
sed '1,2d' intro > temp # delete first 2 lines<br />
tr<br />
tr from-char to-chars<br />
date | tr ' ' '\12' # translate spaces to newlines<br />
tr '[a-z]' '[A-Z]' < intro # translate to upper case<br />
tr -s ' ' ' ' < intro # squeeze out multiple spaces<br />
grep<br />
grep pattern files<br />
grep '*' intro<br />
grep -i 'unix’ intro<br />
grep -v 'UNIX' *<br />
grep -1 '<strong>Unix</strong>' *.c<br />
grep -n 'unix' intro<br />
sort<br />
sort names<br />
sort -u names<br />
sort -r names<br />
sort names -o names<br />
sort -n data<br />
sort +1n data<br />
sort +2n -t: passwd<br />
uniq<br />
uniq in_file out_file<br />
sort names | uniq –d<br />
sort names | uniq –c<br />
# ignore case<br />
# print lines that don‘t contain<br />
# list file names that contain<br />
# precede matches <strong>with</strong> line numbers<br />
# climate duplicates<br />
# reverse<br />
# sort names > names # won't work<br />
# arithmetically<br />
# skip first field<br />
# sort by user id<br />
# remove duplicates<br />
# list duplicates<br />
# count line occurrences<br />
test<br />
test expression<br />
if test "$name" = john<br />
string1 = string2<br />
string1 != string2<br />
# identical<br />
# not identical<br />
38