Tuesday 16 September 2014

One liner linux



Linux -  makes life easy.. lets inspired with Linux



To see a line from big file.
         sed -n 'Xp' theFile, where X is your line number.
e.g          sed -n '42401p' /tmp/bd/soted_voter2.csv

To get more lines.
sed -n  '1127062,+10p' /tmp/gujrat/dhana_gujrat5

To remove a line from big file
sed -i '42401d' /tmp/bd/soted_voter2.csv
Note- If you dont put -i it will show whole output after replacement.

To get Non ascii/foreign characters of a file in red color.
grep --color='auto' -P -n "[\x80-\xFF]" /tmp/bd/soted_voter2.csv

To remove non-ascii chars from a file
tr -cd '\11\12\15\40-\176'  < /tmp/vr_votersorted2.copy > /tmp/bd/cleansortedvoter.copy
To grep pattern wise.
LANG=c;grep INSERT postgresql.log |grep 'Mar  10'|grep -P 'duration: \d\d\d' | cut -d' ' -f4 | cut -d':' -f1,2 | sort | uniq -c


To load data into cdb (only tab supported. )
cdbmake-12 jh jh.tmp < /tmp/jhepic1


To append some text at the end of line in a file.  
awk -F '`' '{print $1 "~2"}' epicmeta_stripped.csv > /tmp/jhepic


To move 1st 15 files from one dir to another.
find . maxdepth 1 -name '*voice*' | head -n 20 | xargs mv -t /tmp/p5


time perl -pi -e 's/0000-00-00 00:00:00//;' *2014*

To configure ip
ifconfig eth0 192.168.19.200/16 up


To Add gateway via command.
`route add default gw 192.168.2.234

To check which process is eating memory. 
ps -e -o pid,vsz,comm= | sort -n -k 2


No comments:

Post a Comment