Thursday, November 29, 2007

Bash shell IFS Internal Field Separator setting and unsetting

When using your "for i in " and you want your "i" to contain
the whole lines instead of space separated fields use the below
at the begining and at the end of your shell script:


export OFS="$IFS" ; export IFS=$'\n';
[ SHELL SCRIPT HERE THAT WORKS on WHOLE LINES ]
export IFS="$OFS"

Wednesday, November 28, 2007

To Strip an xml file for duplicate entries

Basically it greps for all the tags and sorts and prints the duplicates with the below script:


cat *.map.xml | grep include |
sed -e 's/^.*file\s*=\"//' |
sed -e 's/\".*$//' |
sort | uniq -d

Sunday, November 11, 2007

for i ... do ... done bash shell script

This the most usefull shell script I have come across for most of my day to day work on unix:
the oneliner.txt is an ascii file with one entry per line.
I usually modify this file with a vim search-an-replace like:
:%s/^.*\///gc


for i in `cat oneliner.txt`
do grep $i *.map.xml > /dev/null
if [ $? -eq 1 ]
then
echo $i
fi
done