#!/bin/bash # function to convert the reference in alert letter from AGU to Endnote # Usage A2S FileName # http://scriptdemo.blogspot.com sed '/^$/d' $1 > $1.temp sed 's/^[ \t]*//' $1.temp > $1 sed 'n;n;n;n;n;d;' $1 > $1.temp mv $1.temp $1 Nline=$( wc -l $1 | awk '{print $1}' ) Nfile=$( expr $[ $Nline + 1 ] / 5 ) # let "Nfile = $Nfile / 5" or Nfile=$[ $Nfile / 5 ] Nfs=1 while [ ${Nfs} -le ${Nfile} ] do SCHfile=scholar${Nfs}.enw if [ -e $SCHfile ] then echo "$SCHfile exist!" echo "Going on anyway or not [y/n]" read YesNo case $YesNo in y | Y ) # or [y,Y]) rm -f $SCHfile ;; n | N) echo 'Convert aborted!' exit ;; esac fi touch $SCHfile echo '%0 Journal Article' > $SCHfile Topic=$( sed -n "$( expr $Nfs \* 5 - 3 )p" $1) echo "%T $Topic" >> $SCHfile Ln=$( expr $Nfs \* 5 - 4 ) NumName=$( sed -n "${Ln}p" $1 | awk -F\; '{print NF }') Ns=0 echo "NumName is $NumName" while [ $Ns -lt $NumName ] do Ns=$( expr $Ns + 1 ) Name=$(sed -n "${Ln}p" $1 | awk -F\; '{print $NL}' NL=$Ns ) echo "%A $Name" >> $SCHfile done Ln=$( expr $Ln + 2 ) Jname=$( sed -n "${Ln}p" $1 | awk -F, '{print $1}') Vnum=$( sed -n "${Ln}p" $1 | awk -F, '{print $2}' | awk '{print $2}') Nnum=$( sed -n "${Ln}p" $1 | awk -F, '{print $3}' | awk '{print $2}') Pnum=$( sed -n "${Ln}p" $1 | awk -F, '{print $4}') Nyear=$( sed -n "$[ $Ln + 2 ]p" $1 | awk '{print $3}') Uname=$( sed -n "$[ $Ln + 1 ]p" $1 ) echo "%J $Jname" >> $SCHfile echo "%V $Vnum" >> $SCHfile echo "%N $Nnum" >> $SCHfile echo "%P $Pnum" >> $SCHfile echo "%D $Nyear" >> $SCHfile echo "%U $Uname" >> $SCHfile Nfs=$( expr $Nfs + 1 ) done |
Saturday, August 23, 2008
Bash shell demo
Subscribe to:
Post Comments (Atom)
1 comment:
Nfile=$( expr $[ $Nline + 1 ] / 5 )
Topic=$( sed -n "$( expr $Nfs \* 5 - 3 )p" $1)
Name=$(sed -n "${Ln}p" $1 | awk -F\; '{print $NL}' NL=$Ns ) NumName=$( sed -n "${Ln}p" $1 | awk -F\; '{print NF }')
`echo $dd` ==> as command
'echo $dd' ==> string echo
"echo $dd" ==> show value of variable
Post a Comment