Computing.Net > Forums > Solaris > Solairs output file manipulation

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Solairs output file manipulation

Reply to Message Icon

Name: robertanderson
Date: May 28, 2008 at 08:22:58 Pacific
OS: 10
CPU/Ram: 64bit
Product: Sunfire E2900
Comment:

I need to manipulate an output file
C2K248MX - 3
C2K248MX - 3
C2K248MX - 3
C2K248NE - 1
C2K248NN - 2
C2K248NN - 2
C2K248OH - 2
C2K248OH - 2
C2K248OM - 1
C2K248PB - 1
C2K248PD - 1

I only want to see 1 entry with a count rather than an entry for each count,would also like to see the highest first

Any help would be appreciated as Im not a Unix professional and only have limited knowledge... Many thanks




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 28, 2008 at 11:04:18 Pacific
Reply:

A Korn shell, break point report is one way of doing it. I'm assuming the file is already sorted and is 3 fixed length fields:


#!/bin/ksh

# no error checking
rm -f new.file
buffer=""
sum=0
while read f1 f2 f3
do
if [[ -z $buffer ]]
then
buffer="$f1"
sum=$f3
continue
fi
if [[ "$f1" != "$buffer" ]]
then
echo "$buffer $sum"
sum=$f3
else
((sum=sum+$f3))
fi
buffer="$f1"
done < out.file > new.file
echo "$buffer $sum" >> new.file
# end script

by default, the sort command sorts in descending order:

sort new.file


0

Response Number 2
Name: robertanderson
Date: May 28, 2008 at 11:17:00 Pacific
Reply:

Many thanks for the prompt reply
Not sure if I can combine this with current script in use.
Current script:
#!/usr/bin/ksh
EVTLOG=evtlog.`date +"%Y-%m-%d"`
(Sets date back to previous day)

if [ $# -ne 1 ]
then
# Assume using todays log
logfile=$LOGS/mq/$EVTLOG
else
logfile=$1
fi

flipped=`cat $logfile | grep -i -c "Dual Site Indicator changed"`
print "Operating with file : $logfile"
print "Total Site Switches : $flipped "
for atmflip in $(cat $logfile | grep -i "Dual Site Indicator changed" | cut -c382-389 | sort)
do
atmflipcount=`cat $logfile | grep -i "Dual Site Indicator changed" | grep -c $atmflip`
print "$atmflip - $atmflipcount"
done.

That last print statement produces the results you see at the begining need to arrange that to produce a list with entry and count only -
Many thanks for trying though


0

Response Number 3
Name: nails
Date: May 28, 2008 at 12:44:24 Pacific
Reply:

Myself, I'm very careful with changing production code so I try to limit changes when I can. You don't say how the output of your Current script is captured - a file perhaps?

If so, you could use that file as the input file of the script I provided. I called the file out.file.

Another way is to encorporate my changes into your current script. To minimize these changes, send the output of your last for loop to a temporary file:

for atmflip in $(cat $logfile | grep -i "Dual Site Indicator changed" | cut -c382-389 | sort)
do
atmflipcount=`cat $logfile | grep -i "Dual Site Indicator changed" | grep -c $atmflip`
print "$atmflip - $atmflipcount"
done > /tmp/out.file
# note sending output to /tmp/out.file

Now, add this code to the end of you Current script:


# untested
rm -f /tmp/new.file
buffer=""
sum=0
while read f1 f2 f3
do
if [[ -z $buffer ]]
then
buffer="$f1"
sum=$f3
continue
fi
if [[ "$f1" != "$buffer" ]]
then
echo "$buffer $sum"
sum=$f3
else
((sum=sum+$f3))
fi
buffer="$f1"
done < /tmp/out.file > /tmp/new.file
echo "$buffer $sum" >> /tmp/new.file
# end script

If the output of your Current script is presently captured in a file then you can eliminate redirecting to /tmp/new.file


0

Response Number 4
Name: Sujan (by Sujan Banerjee)
Date: September 5, 2008 at 05:58:52 Pacific
Reply:

Hi Robert,
Sorry for the late reply,
Not sure if my suggestion will be of any help.
Here is a one-liner for what u have asked for.
Your file is:-
C2K248MX - 3
C2K248MX - 3
C2K248MX - 3
C2K248NE - 1
C2K248NN - 2
C2K248NN - 2
C2K248OH - 2
C2K248OH - 2
C2K248OM - 1
C2K248PB - 1
C2K248PD - 1

Now here is the oneline solution for your problem:-
bash-2.03# cut -d"-" -f1 list_2|sort|uniq -c|sort -nr
3 C2K248MX
2 C2K248OH
2 C2K248NN
1 C2K248PD
1 C2K248PB
1 C2K248OM
1 C2K248NE

Hope its of any use to u,

Regards,
Sujan Banerjee


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Solairs output file manipulation

Need to compare two files www.computing.net/answers/solaris/need-to-compare-two-files/5030.html

cat vs. read www.computing.net/answers/solaris/cat-vs-read/876.html

Automatic User Number Tracking www.computing.net/answers/solaris/automatic-user-number-tracking/3268.html