Sponsored Content
Full Discussion: Count help - newbie
Top Forums Shell Programming and Scripting Count help - newbie Post 102438 by britney on Friday 17th of March 2006 05:35:59 PM
Old 03-17-2006
Count help - newbie

I have a flat file sort by Phonenumber and Bigin call fileA.txt
Phonnumber|Begin|Endca|D1|D2|Diff
4159061234|10:00|10:01|a1|a2|60
4159061234|10:00|10:06|b1|b2|360

4159061234|10:05|10:06|c1|c2|60
4159061234|10:12|10:15|d1|d2|180
3045678934|10:25|10:28|x1|x2|180
3045678934|10:25|10:30|y1|y2|300

3045678934|10:28|10:31|z1|z2|180
....................

How do I write a code in ksh so it will check the
phone number and if phone number with same begin call then count
and give outout.txt as a result

Phonnumber|Begin|Endca|D1|D2|Call Times
3045678934|10:25|10:28|x1|x2|2
3045678934|10:28|10:31|z1|z2|1
4159061234|10:00|10:01|a1|a2|2
4159061234|10:05|10:06|c1|c2|1
4159061234|10:12|10:15|d1|d2|1

......................................

Thanks

===


Here is my code
Quote:
grep "|" fileA.txt | sort -t"|" +0 -1 +2 -3 +5 -6 |
awk -F"|" '{

ani=$1;
betime=$2;
if ((ani != ani0) && (betime != betime0)) {
any0 = ani;
betime0 = betime;
date=$2;
entime=$3;
D1=$4
D2=$5;
diff=$6;
count = "0";
if ( diff <= 600 ) {
count = count + 1;
printf "%s,%s,%s,%s,%s,%s\n",ani,betime,entime,D1,D2,count >> output.txt
}
}
}'
but my asnswer is
3045678934,10:25,10:28,x1,x2,1
3045678934,10:28,10:31,z1,z2,1
4159061234,10:00,10:01,a1,a2,1
4159061234,10:05,10:06,c1,c2,1
4159061234,10:12,10:15,d1,d2,1

Last edited by britney; 03-17-2006 at 08:16 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies

2. Shell Programming and Scripting

help a newbie count!

hello, I would really appreciate any help with this! i have files in the format ####_*.dat so like 2913_dsssf_sdfsdf_sddsf.dat 3208889423_lk3mnf_sdfe.dat what im trying to do is extract the number from the start of the file (end of number will always be followed by _ ) and copy the file... (3 Replies)
Discussion started by: jayydee
3 Replies

3. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

4. UNIX for Dummies Questions & Answers

UNIX newbie NEWBIE question!

Hello everyone, Just started UNIX today! In our school we use solaris. I just want to know how do I setup Solaris 10 not the GUI one, the one where you have to type the commands like ECHO, ls, pwd, etc... I have windows xp and I also have vmware. I hope I am not missing anything! :p (4 Replies)
Discussion started by: Hanamachi
4 Replies

5. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

6. Shell Programming and Scripting

perl newbie . &&..programming newbie

Hi, I am new to programming and also to perl..But i know 'perl' can come to my rescue, But I am stuck at many places and need help..any small help is much appreciated... below is the description of what i intend to acheive with my script. I have a files named in this format... (13 Replies)
Discussion started by: xytiz
13 Replies

7. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

8. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

9. Shell Programming and Scripting

Compare file1 header count with file2 line count

What I'm trying to accomplish. I receive a Header and Detail file for daily processing. The detail file comes first which holds data, the header is a receipt of the detail file and has the detail files record count. Before processing the detail file I would like to put a wrapper around another... (4 Replies)
Discussion started by: pone2332
4 Replies

10. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 06:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy