- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script enhancement
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 09:27 PM
11-17-2003 09:27 PM
I have a problem right now. I have a list of files: filea, fileb, filec-------* (can be more). Each file has data example below delimited by comma ","
2003-11-09 04:13:07,baddete,30000,5,35,2003-11-08 23:59:29
2003-11-09 04:12:43,gerry,30000,35,85,2003-11-08 23:59:14
2003-11-09 04:13:32,lance,30000,35,35,2003-11-08 23:59:49
2003-11-09 04:13:32,lance,30000,35,178,2003-11-08 23:59:49
2003-11-09 04:13:32,lance,30000,35,605,2003-11-08 23:59:49
I want to make a script that prints output
example the name of the person $2 (example gerry, lance, badette) and the number of occurence where $1 (date),$4 (can be 5, 35 from example above) and $3 (example 30000)occured are the same. Also prints the $1,$4, & $3
Ouput file sample
lance 2 2003-11-09 04:13:32 30000 35
$2 (twice) $1 $3 $4 (which means that this event appears twice in all files*)
Can you help me here? thanks so much.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 10:19 PM
11-17-2003 10:19 PM
Re: Script enhancement
use awk
awk -v FS="," '{print $1 " "$4" "$3 }'
filelist
or
for in in file*
do
awk -v FS="," '{print $1 " "$4" "$3 }' $i
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 10:23 PM
11-17-2003 10:23 PM
Re: Script enhancement
That's a tall order.
I can get you started with
for f in file?
do
awk -F, '{printf "%s 1 %s %s %s\n", $2, $1, $3, $4}' $f >> intermediate_file
done
Then you'd have to do some sorting on intermediate_file to find the duplicates and sum them.
-- Graham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 10:31 PM
11-17-2003 10:31 PM
Re: Script enhancement
cd dir
cat file* > file_all
while read -r line
do
DATE=echo $line | awk ' FS = "," { print $1 } '`
NAME=`echo $line | awk ' FS = "," { print $2 } '`
VAL1=`echo $line | awk ' FS = "," { print $3 } '`
VAL2==`echo $line | awk ' FS = "," { print $4 } '`
COUNT=`cat file_all | grep "$DATE" | grep $VAL1 | grep -c $VAL2`
echo "$NAME $COUNT $DATE $VAL1 $VAL2"
NB: NOT TESTED
TS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 10:35 PM
11-17-2003 10:35 PM
Re: Script enhancement
I cat file* > masterfile
Now I need to get how many occurences for $2
where $1, $3, $4 are the same.
Output file can be
$2 occurences= x $1 $3 $4
lance occurence= 2 2003-11-09 04:13:32 30000 35
The problem is how can I print x.
PS will only print greater than 1 occurence.
If you can help me use awk much faster.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 11:05 PM
11-17-2003 11:05 PM
Re: Script enhancement
sort -d, -k 1,3,4,2 masterfile | awk '
prev == $1 $3 $4 { count++; }
prev != $1 $3 $4 {
printf "%s occurences = %d %",
prevlab,count,prev;
prev=$1 $3 $4;
prevlab=$2;
count=0
}
END {
printf "%s occurences = %d %",
prevlab,count,prev;
}'
Depending on what you find most important, you could change the sort order from 1,3,4,2 to 2,1,3,4, meaning that you get output per column 2 instead of per date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 11:26 PM
11-17-2003 11:26 PM
Re: Script enhancement
Error occured can be in the usage.
sort: illegal option -- ,
Usage: sort [-AbcdfiMmnru] [-T Directory] [-tCharacter] [-y kilobytes] [-o File]
[-k Keydefinition].. [[+Position1][-Position2]].. [-z recsz] [File]..
occurences = 0 %
root#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 11:26 PM
11-17-2003 11:26 PM
Re: Script enhancement
in my reply the content of varaible COUNT=x
so to print only x>1 add the following
if [ $COUNT -gt 1 ]
echo ....
else
:
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 11:32 PM
11-17-2003 11:32 PM
Solutionttt.awk
# begin ttt.awk
BEGIN {
LAST=""
COUNT=0
FS="|"
}
NR==1 { LAST=$0
LAST1=$1
LAST2=$2
COUNT= 1 }
NR > 1 {
if ( LAST == $0 )
{
COUNT +=1
}
else
{
print LAST1 " " LAST2 " Count : " COUNT
COUNT=1
LAST=$0
LAST1=$1
LAST2=$2
}
}
# cut here
example:
files tt1 tt2
cat tt? | awk -v FS="," '{print $2 "|"$1" "$4" "$3 }' | sort |awk -f ttt.awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 11:39 PM
11-17-2003 11:39 PM
Re: Script enhancement
sort -t "," -k 1,3,4,2 | .....
(-t instead of -d)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2003 11:42 PM
11-17-2003 11:42 PM
Re: Script enhancement
printf "%s occurrence = %d %s\n",prevlab,count,prev
Sorry.