If you need to get some text which is in file between two lines you could use awk for this. You may need it while analyzing access logs to fix some issue, for instance. Here’s how you could do it: awk ‘/2012:00:20:49/, /2012:00:35/’ access_log > output It’s a simple and convenient way.
All posts tagged tips
Bash: check if a zip or a rar file has password-protection
If you need to check if zip or rar file has password protection you can do it this way. For zip fip: crypted=$( 7z l -slt — $file | grep -i -c “Encrypted = +” ) if [ “$crypted” -eq “1” ]; then protected=1 fi And for rar: unrar x -p- -y -o+ “$file” 1>…
AWK: getting last column value
If you need to get value of last column in awk you can use built-in variable NF which means the number of fields in record. awk ‘$(NF) !~ /-/ { print $0 }’ access_log Or next, if you need next to the last field. And so on. awk ‘$(NF-1) != /-/ { print $0 }’…
Bash: sort IP addresses
It’s very easy sorting IP-list. For example you have file ‘ip-list’. To sort IP’s redirect file contents to following sort command. Also collect only unique IP’s in yours list. cat ip-list | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq >> sorted-ips Didn’t find the answer to your question?…
How to exclude directories while using rsync
Sometimes when you copy a lot of data with rsync you may to exclude some sub-directories. You can do this by using –exclude. For instance, you want to copy files from /mnt to /home/destination_dir/, and you want to exclude directory /mnt/dir1/dir2/. rsync -az –exclude=’dir1/dir2/’ /mnt/ /home/destination_dir/ A lot of users do mistake when specifing path.…