Home > Uncategorized > My favourite one liners.

My favourite one liners.

Execute script that is available in URL
curl -sSL https://get.docker.io/ubuntu/ | sudo sh

Find all the file extensions recursively from current folder.

find -type f | awk -F. ‘{print $NF}’ | sort | uniq -c | sort -nr

recursively unzip files
find . -name “*.gz” -exec gunzip ‘{}’ \;

Bulk rename of gz to xml
ls -1 | awk -F. ‘{print “mv \”” $1″.gz\””, “\””$1″.xml\””}’

Sort based on substring of filename
find -type f -name \*gz | awk -F”/” ‘{print substr($4,1,16)}’ | sort -nr

Find the number of files group by directory
find . -type d -exec sh -c “fc=\$(find ‘{}’ -type f | wc -l); echo -e \”\$fc\t{}\”” \; | sort -nr

Find if className available in any of the jar file
find /home/user/project/ -name “dependency*.jar” -exec jar tvf ‘{}’ \; | grep -i “classname”

Count number of lines in all successive directory in certain files alone.
for file in `find -name “InputLog.csv”`; do echo $file; grep -v ‘NotInterestedLines’ $file | grep -E -w -c InteresteLine; done

Print rows into columns
awk ‘BEGIN { FS = “,” }; {for (i=1;i<NF; i++) {print i,$i} }' FavourteCSV.txt | head -10

Grep set of string in single file.
while read i ; do egrep “,$i,” input_text.log; done setOfStringInMultipleLine.txt &

Or Generate egrep using following command
cat files.txt | sort -r | tr ‘\n’ ‘|’ | sed s’/.$//’ | sed s’/|/_|_/g’ | sed s’/^/_/’ | sed s’/$/_/’ | sed s’/^/egrep “(/’ | sed s’/$/)”/’

sdiff -w 175 file1.csv file2.csv |egrep ‘\||>| diff.txt

Find which svn commit, a souce line removed/added inside code/configuration file.
C:\Mohan\Workspaces\workspace\TRUNK\application-component\src\main\resources>svn log -l 30 -v –diff configuration_server.xml > svn_log_entries.txt
cat svn_log_entries.txt | grep “ChangedLine”

Find all the Epoch seconds (date) that are not not fall in 10:00AM
gawk ‘{print $1, $2, $3, strftime(“%c”, $6)}’ isProblematic.txt | grep -v “10:00:00 AM”

Given key value tex file, replace all the key with value recusively in text file.
while read line;do export oldTime=`echo $line | awk ‘{print $1}’`; export newTime=`echo $line | awk ‘{print $2}’`; find ./ -type f -name “*.properties” -exec perl -p -i -e s/$oldTime/$newTime/g {} \; ; done < /var/tmp/Mohan/find_and_replace/diff_time.csv

echo “[{\”toto\”:5},{\”toto2\”:5}]” | python -c ‘import json,sys;obj=json.load(sys.stdin);print str(obj[0][“toto”]) + “,” + str(obj[0][“toto”])’

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: