Cli favourites

From bibbleWiki
Jump to navigation Jump to search

compare two files

diff -y -w --suppress- workrequestAll.orig workrequestAll.new

convert files from dos to unix

find -name "*.cpp" | xargs perl -pi -e 's/\r\n/\n/g'

find large files

find /home/iwiseman -size 10M 

gawk usage

This nicely removes the total line in ls and prints the filename

ls -l | sed /^total/d |gawk  {'print $9'}

sed search and replace

Replace text in file

sed -i -e 's/fff/ddd/g' iain.txt

print list of filenames using awk

ls -l |gawk -F \  {'print $9,$5'}

Get parameters using grep and RegEx

I did this on a node js program which uses appCongfig to store config.

...
ws/bcDataSend.ts:if (!appConfig.KEY_PEM) throw new Error('You must provide a server key')
ws/bcDataSend.ts:if (!appConfig.KEY_CERT) throw new Error('You must provide a server certificate')
ws/bcDataSend.ts:const key = fs.readFileSync(appConfig.KEY_PEM)
ws/bcDataSend.ts:const cert = fs.readFileSync(appConfig.KEY_CERT)
...

Using this we can

  • extract all occurrences of appConfig
  • put each occurrence on a separate line
  • regex all appConfig. until non [A-Z] -o only outputs the matches
  • sort and get unique values
grep -r  "appConfig\."  |sed -e  s/appConfig/\\nappConfig/g |grep appConfig | egrep -o  '^appConfig.[A-Z_]+' |sort | uniq