Do’s and Dont’s in shell scripting
December22
Do’s and Dont’s in shell scripting
1) Dont use Grep and Cat command together
Wrong way :
1 | $cat filename | grep "pattern" |
Correct way :
1 | $grep "pattern" filename |
2) Dont use cat,grep and wc commands together
Wrong way :
To count the number of occurence
1 | $cat filename | grep "pattern" | wc -l |
Correct way :
1 | $grep -c "pattern" filename |
3) dont use sort and uniq together ( to eliminate the duplicate entires )
Wrong way :
1 | $sort filename | uniq |
Correct way :
1 | $sort -u filename |
4) Dont use grep and awk together
wrong way :
1 | $ grep "pattern" filename | awk '{print $1}' |
correct way :
1 | $ awk '/pattern/ {print $1}' filename |
5) Dont use ls in for loop ( to manipulate the files )
wrong way :
1 2 | for i in `ls` ; do echo $i; done for i in `ls *.txt`; do echo $i; done |
Correct way :
1 2 | for i in *; do echo $i; done for i in *.txt; do echo $i; done |
Recent Comments