Cli favourites: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== compare two files == | |||
<syntaxhighlight lang="bash"> | |||
diff -y -w --suppress- workrequestAll.orig workrequestAll.new | |||
</syntaxhighlight> | |||
== convert files from dos to unix == | |||
<syntaxhighlight lang="bash"> | |||
find -name "*.cpp" | xargs perl -pi -e 's/\r\n/\n/g' | |||
</syntaxhighlight> | |||
==find large files== | ==find large files== | ||
Line 16: | Line 26: | ||
ls -l |gawk -F \ {'print $9,$5'} | 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. | |||
<syntaxhighlight> | |||
... | |||
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) | |||
... | |||
</syntaxhighlight> | |||
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 |
Latest revision as of 22:12, 24 January 2023
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