Extract the requests from an access_log that match the IPs from a list.
We have your common log formatted access_log. We wish to get all the requests that match the IPs from a list of IPs in a text file called ip_list.txt.# awk '/.*/ {print "cat access_log | grep "$1" >> extract.txt "}' ip_list.txt | sh
Find out the Files That Contain Certain Text
It is common to want all the names of the files that contain a certain text. For instance, say inside a script directory you want to find all the scripts that contain a certain database name or a piece of text.
find . -name '*.sh' | xargs grep -il '_KingKongDB'
Find out required libraries for C/C++ functions
Here we want to use the function sem_init, but we are not too sure of what libraries to link with. We can use 'nm' and 'grep' on the libraries (/usr/lib on linux).# nm --print-file-name /usr/lib/* 2> /dev/null |grep sem_init
This command will return results with strings containing '/usr/lib/libpthread.a'. From this you know that you have to link with the option -pthread.
Replace a value in multiple files and write the output files to a new directory
In this example we have xml files such as Nokia-220s.xml, Nokia-2330.xml etc. We want to replace the value 'Spec-Handler' in these files with a new value called 'Nokia-WAP' and then write these files into a new directory called 'new'# ls -l Nokia* |awk '{print "sed","'\''s/Spec-Handset/Nokia-WAP/g'\'' " $9 " >new/"$9}' |sh
Replace the newline ('\n') character at the end of a line with something else (a comma in this case)
cat addresses.txt | tr '\n' ','
find . -type f | grep -v '\.svn' | xargs perl -pi -e 's/\r\n/\n/g'
cat access_log | grep 217.124.181.30 |sed -n 's/.*\("[a-zA-Z][^"]*"\)$/\1/pg'
