script the output with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script the output with awk
# 1  
Old 10-02-2006
Data script the output with awk

Please i need your help.

i made this script with awk, this scripts count and list a pattern for each directory in the output as shown. but not as desired. i want the output will be listed in a tabular way, using awk:

cuenta_cdrs()
{
for dir in *
do
cd $dir
for file in *
do
if [ -f $file ]
then
cat listacdrs|awk '
BEGIN {print "dia", "\t", "Cantidad"}
$1 == prev {totaldia+=1}
$1 != prev {print prev,totaldia;totaldia=1;prev=$1;filas=filas+1}'
fi
done
cd ..
done
}

OUTPUT
dia Cantidad

01/09/2006 1275
02/08/2006 1285
03/08/2006 1310
04/08/2006 1300
05/08/2006 1415
dia Cantidad

01/09/2006 1275
02/08/2006 1285
03/08/2006 1310
04/08/2006 1300
05/08/2006 1415
06/08/2006 1265
dia Cantidad

01/09/2006 1275
02/08/2006 1285

But i want the output to be this way:

OUTPUT DESIRED
dia Cantidad dia cantidad

01/09/2006 1275 01/09/2006 1275
02/08/2006 1285 02/08/2006 1285
03/08/2006 1310 03/08/2006 1310
04/08/2006 1300 04/08/2006 1300
05/08/2006 1415 05/08/2006 1415

Thanks
# 2  
Old 10-02-2006
Please ,show us the format of your input file.
# 3  
Old 10-02-2006
Data

Quote:
Originally Posted by Klashxx
Please ,show us the format of your input file.
Th e input file is called listacdrs and the format is:

01/10/2006 08:20 CF004
01/10/2006 08:25 CF006
..
04/10/2006 04:23 CF1020

---
DD/MM/YYY HH:MM CONCSECUTIVE NUMBER.
This purpose is count and list the number of consecutives per day usin awk, the results are ok with this script but i need to b elisted or output in a tabaular way for each directory but not be listea by pages.
I apprecitae your help please.
# 4  
Old 10-02-2006
you can use paste command to do that
# 5  
Old 10-03-2006
Try this:

Code:
cuenta_cdrs()
{
 for dir in *
 do
  cd $dir
  for file in * 
  do 
   if [ -f $file ]
   then
    awk '
    BEGIN {print "dia", "\t", "Cantidad"}
    $1 == prev {totaldia++}
    $1 != prev {printf("%s\t%s\n",prev,totaldia);totaldia=1;prev=$1;filas++}' listacdrs
   fi 
  done
  cd .. 
 done
}

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

2. UNIX for Beginners Questions & Answers

awk Script Output Help

My code is listed below, I'm trying to figure out what the problem is and what I can do to fix it. The output i'm getting is: Name Low High Average 0 0 0.00 The correct output I want is the name of the Assignment, the lowest score and highest score obtained, and the Average Score... (10 Replies)
Discussion started by: Marquez3105
10 Replies

3. UNIX for Dummies Questions & Answers

Combine Both Output from the awk Script

Hi, Is there anyway to combine output from the awk scripting. file01.txt: AUE_CHMOD AUE_CHOWN AUE_CHROOT AUE_CONNECT AUE_ACCEPT AUE_FCHOWN AUE_FCHMOD AUE_SETREUID AUE_SETREGID AUE_FCHROOT AUE_PFEXEC AUE_SETUID AUE_NICE AUE_SETGID (9 Replies)
Discussion started by: alvinoo
9 Replies

4. Shell Programming and Scripting

awk script not producing output

Hi, I have a text file with some thousands of rows of the following kind (this will be referred to as the inputFileWithColorsAndNumbers.txt): Blue 6 Red 4 Blue 3 Yellow 4 Red 7 Colors in the left column and a number in the right one for each line. I want to run an awk... (5 Replies)
Discussion started by: Zooma
5 Replies

5. Shell Programming and Scripting

awk Script to format output

Hi all, I'm fairly new to this and learning along the way, so bare with me... I'm trying to format the output from a script to be more read-friendly. The output contains more servers and more processes but for as example it will do: Server: Test1 ... (4 Replies)
Discussion started by: Bobsonm
4 Replies

6. Shell Programming and Scripting

awk script to search output for a value and print

GOODNUMBERS="1 2 3 4 5 6 3 3 34 34 5 66 12" BADNUMBERS="7 3 12 5 66" for eachnum in `echo ${GOODNUMBERS}` do echo ${BADNUMBERS} | gawk -v threshold=${eachnum} '$1 != threshold' done what im trying to do with the above is, i want to print numbers that are in the GOODNUMBERS... (10 Replies)
Discussion started by: SkySmart
10 Replies

7. Shell Programming and Scripting

How to get fields and get output with awk or shell script.?

I have a flat file A.txt with field seperate by a pipe 2012/11/13 20:06:11 | 284:hawk pid=014268 opened Locations 12, 13, 14, 15 for /home/hawk_t112/t112/macteam/qt/NET12/full_ddr3_2X_FV_4BD_1.qt/dbFiles/t112.proto|2012/11/14 15:19:26 | still running |norway|norway 2012/11/14 12:53:51 | ... (6 Replies)
Discussion started by: sabercats
6 Replies

8. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

9. Shell Programming and Scripting

Colon in awk script output

I'm using AIX 5.3 and running a awk replace to modify data as follows: echo 1234: 1234 123 123 444 555 666 7777 | awk '/^:/{split($2,N);n=N} {n=$1} {sub(n,n+10000000)}1' 10001234 1234 123 123 444 555 666 7777 dumb question.. how do I get the colon back in, so it outputs 10001234: 1234... (4 Replies)
Discussion started by: say170
4 Replies

10. Shell Programming and Scripting

Format output using awk in script.

Guys, I have a script which hits the database and pulls the information that I need into files. Now I want to format these files to make them easy to read. The sample format of the file will be like.... <Start_of_File> Header1 .....xsdfsfa...adfa...... Header2 ....afefas .aefaefsdf...... (8 Replies)
Discussion started by: bperl
8 Replies
Login or Register to Ask a Question