|
Home > Archive > Unix Shell > January 2006 > Preserving original Tabs and separators...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Preserving original Tabs and separators...
|
|
| contracer11@gmail.com 2006-01-29, 9:30 pm |
| Please, could you tell me how preserve tabs and space separators in
this script ?
(read command don=B4t preserve original separatos from jobs4.lis file):
while true
do
clear
/usr/openv/netbackup/bin/admincmd/bpdbjobs -report -header > jobs4.lis
echo
grep Active jobs4.lis
echo
cat jobs4.lis | grep -i "`date +%m/%d/06`" | while read a b c d e f g
h i j k
do
if [ $e -gt "0" ]
then
echo "$a $b $c $d $e $f $g $h $i $j $k"
fi
done
sleep 60
done
Thanks a lot !
| |
| Janis Papanagnou 2006-01-29, 9:30 pm |
| contracer11@gmail.com wrote:
> Please, could you tell me how preserve tabs and space separators in
> this script ?
> (read command donīt preserve original separatos from jobs4.lis file):
>
> while true
> do
> clear
> /usr/openv/netbackup/bin/admincmd/bpdbjobs -report -header > jobs4.lis
> echo
> grep Active jobs4.lis
> echo
> cat jobs4.lis | grep -i "`date +%m/%d/06`" | while read a b c d e f g
> h i j k
> do
> if [ $e -gt "0" ]
> then
> echo "$a $b $c $d $e $f $g $h $i $j $k"
> fi
> done
> sleep 60
> done
>
> Thanks a lot !
>
Replace everything from 'cat' until the first 'done' by
awk -v d=$(date +%m/%d/06) '$0 ~ d && $5 > 0' jobs4.lis
(this code is untested)
Janis
| |
| Benjamin Schieder 2006-01-29, 9:30 pm |
| contracer11@gmail.com wrote:
> Please, could you tell me how preserve tabs and space separators in
> this script ?
> (read command donīt preserve original separatos from jobs4.lis file):
You could try modifying the script like this:
> while true
> do
> clear
> /usr/openv/netbackup/bin/admincmd/bpdbjobs -report -header > jobs4.lis
> echo
> grep Active jobs4.lis
> echo
oldifs=${IFS}
IFS=""
grep -i "`date +%m/%d/06`" jobs4.lis | while read line
> do
IFS=${oldifs}
read a b c d e rest < <( echo "${line}" )
> if [ $e -gt "0" ]
> then
echo "${line}"
IFS=""
> fi
> done
> sleep 60
> done
This is untested, but I'm quite sure it works. It also gets around a useless use
of cat, thought I think that there might be a more elegant way to split up
${line} into its parts.
Greetings,
Benjamin
--
The Nethack IdleRPG! Idle to your favorite Nethack messages!
http://pallas.crash-override.net/nethackidle/
| |
| Chris F.A. Johnson 2006-01-29, 9:30 pm |
| On 2006-01-25, contracer11@gmail.com wrote:
> Please, could you tell me how preserve tabs and space separators in
> this script ?
> (read command donīt preserve original separatos from jobs4.lis file):
>
> while true
> do
> clear
> /usr/openv/netbackup/bin/admincmd/bpdbjobs -report -header > jobs4.lis
> echo
> grep Active jobs4.lis
> echo
> cat jobs4.lis | grep -i "`date +%m/%d/06`" | while read a b c d e f g
> h i j k
> do
> if [ $e -gt "0" ]
> then
> echo "$a $b $c $d $e $f $g $h $i $j $k"
> fi
> done
grep -i "`date +%m/%d/06`" jobs4.lis |
while IFS= read -r line
do
set -f
set -- $line
[ "$5" -gt 0 ] && printf "%s\n" "$line"
done
Or:
grep -i "`date +%m/%d/06`" jobs4.lis | awk '$5 > 0 { print }'
> sleep 60
> done
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| John W. Krahn 2006-01-29, 9:31 pm |
| contracer11@gmail.com wrote:
> Please, could you tell me how preserve tabs and space separators in
> this script ?
> (read command donīt preserve original separatos from jobs4.lis file):
>
> while true
> do
> clear
> /usr/openv/netbackup/bin/admincmd/bpdbjobs -report -header > jobs4.lis
> echo
> grep Active jobs4.lis
> echo
> cat jobs4.lis | grep -i "`date +%m/%d/06`" | while read a b c d e f g
> h i j k
> do
> if [ $e -gt "0" ]
> then
> echo "$a $b $c $d $e $f $g $h $i $j $k"
> fi
> done
> sleep 60
> done
perl -lne'
BEGIN{ chomp( $date = `date +%m/%d/06` ) }
/$date/ && /((?:\S+\s+){4}(\S+)(?:\s+\S+){6})/ && $2 > 0 && print $1
' jobs4.lis
John
--
use Perl;
program
fulfillment
|
|
|
|
|