Sponsored Content
Top Forums Shell Programming and Scripting Formatting a file using shell script Post 302542322 by aigles on Wednesday 27th of July 2011 08:27:13 AM
Old 07-27-2011
The output format is not fixed :
Code:
nawk -F '[,/]'  -v Threshold=0.1 '
   NR==1 {
      for (c=2; c<NF; c++) Times[c-1] = $c;
      TimesCount = NF-2;
      next;
   }
   {
      cnt_total = $(NF-1)+0;
      avg_total = $NF+0;
      if (avg_total < Threshold) next;
      svcname   = $1;
      out       = "";
      field     = 3;
      for (c=1; c<TimesCount; c++) {
          cnt = $(field-1);
          avg = $field;
          if (avg > Threshold) out = sprintf("%s %s (%s/%s)", out, Times[c], cnt, avg);
          field += 2;
      }
      if (out) printf "%s %s  Avg %s/%s\n",  svcname, out, cnt_total, avg_total;
   }
' deo.txt

Output:
Code:
svc300  2a-3a (78/16622.60)  Avg 4100/316.27



Please show us the required output for the following sample datas :
Code:
SVCNAME,12m-1a,1a-2a,2a-3a,3a-4a,5a-6a,6a-7a,7a-8a,8a-9a,9a-10a,10a-11a,11a-12n,12n-1p,13p-14p,14p-15p,15p-16p,16p-17p,17p-18p,18p-19p,19p-20p,20p-21p,21p-22p,22p-23p,11p-12m, TOTALS
svc100,145/0.04,124/0.4,72/0.04,2/0.14,2/0.18,67/0.4,299/0.04,392/0.04,419/0.04,497/0.04,418/0.04,705/0.03,831/0.02,118/0.04,149/0.04,109/0.04,113/0.04,44/0.04,56/0.04,74/0.04,16/0.04,23/0.04,112/0.4,       4787/0.3
svc200,159/0.07,166/0.09,89/0.10,6/0.06,0/0.00,33/0.11,250/0.12,361/0.08,344/0.09,592/0.07,480/0.07,422/0.08,222/0.09,126/0.07,118/0.07,148/0.07,202/0.05,86/0.05,88/0.05,76/0.05,18/0.06,15/0.08,121/0.06,  4122/0.08
svc300,157/0.04,154/0.04,78/16622.60,4/0.03,4/0.06,41/0.04,197/0.06,328/0.04,317/0.04,539/0.04,478/0.04,402/0.04,227/0.04,148/0.04,156/0.04,185/0.04,242/0.03,111/0.03,120/0.03,82/0.03,17/0.04,17/0.03,96/0.03,  4100/316.27

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting lines in shell script

I have a file with the below lines 1521 1522 1523 1524 1525 1526 ... 174 lines all numbers like above. I want the above file to appear as below. 1521,1522,1523,1524..... All the numbers should be separated by comma. Pls tell me how to do this .... Thanks in advance. (8 Replies)
Discussion started by: dreams5617
8 Replies

2. Shell Programming and Scripting

formatting a file using shell script

Hi I have to do the following.I have to format a file test.t The contents are # Header 1231 xyz asdf asdapsdcsd //string1 = "pqrs" //string1 = "abcd"; //info //string1 = "*pqrs"; //add string1 = "#123"; //sub //string1 = "#1234567890" data = check(string1) //string1 = "#1234567890"... (12 Replies)
Discussion started by: gopsman
12 Replies

3. Shell Programming and Scripting

Formatting the text file using shell script

How to add the filename to end of each line with | as seperator, except first and last line of the file(s) in directories(with diff tree structure) using shell script?. And also how to replace a list of strings with another set of strings, which is present in a file?. Kindly help out on... (1 Reply)
Discussion started by: av_vinay
1 Replies

4. Shell Programming and Scripting

Date formatting in shell script

Hi, I am writing a script and I need to calculate last weeks date. I get the current date as; today=`date '+%Y%m%d'` and I need last week inthe same format. Thanks, (2 Replies)
Discussion started by: ozum
2 Replies

5. Shell Programming and Scripting

Shell Script Problems, Lose formatting when copy pasting from formatted file.

Hello, I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating! Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a... (13 Replies)
Discussion started by: facetoe
13 Replies

6. Shell Programming and Scripting

formatting a shell script

there is one shell which calls for different sql scripts. output of different are formatted in frame like structure.i want columnar wise formatting to be done in such a manner that output of one sql may be comon input of rest sqls . ERC DML Closure Date ER DML SAP Transfer Date ... (0 Replies)
Discussion started by: arc
0 Replies

7. Shell Programming and Scripting

AWK/Shell script for formatting data in a file

Hi All, Need an urgent help to convert a unix file in to a particular format: **source file:** 1111111 2d2f2h2 3dfgsd3 ........... 1111111 <-- repeats in every nth line. remaining all lines will be different 123ss41 432ff45 ........... 1111111 <-- repetition qwe1234 123weq3... (1 Reply)
Discussion started by: rajivnairfis
1 Replies

8. Shell Programming and Scripting

Formatting File Using Shell Script

Hi Team, We have a requirement where we need to format input file using shell script by meeting the below conditions. 1. 1. Ignore first 549 characters of that file. 2. 2. After that we need to make a file of 100 characters per line, repeat it until the 3rd ... (16 Replies)
Discussion started by: ataneja7
16 Replies

9. Shell Programming and Scripting

Formatting a file using shell script

Hi, Please find the below lines of a file B1/OT "GIB10" 837 130308 1351 MONORONOUS DIGI PATH FAULT SUPER B1/OT "GIB10" 520 130418 1537 MONORONOUS DIGI PATH FAULT SUPER B1/XT "GIB10" 762 130421 0653 TV Y-CEIVER ADMIN RXOCF-62 241_OKEBOLE_NEW 1 B1/XT "GIB10" 385 130425 1931 TV Y-CEIVER... (2 Replies)
Discussion started by: Ardhendu
2 Replies

10. Shell Programming and Scripting

Need some help in formatting answer of shell script

Dear all, I am new to shell scripting and have tried to make a small program for fun sake that tells age from the last number of cell phone and birth year. At the end we get a final 3 digit number and the first digit represents the last digit of cell phone and rest 2 numbers shows age. eg. 423... (4 Replies)
Discussion started by: stg44
4 Replies
ucblinks(1B)					     SunOS/BSD Compatibility Package Commands					      ucblinks(1B)

NAME
ucblinks - adds /dev entries to give SunOS 4.x compatible names to SunOS 5.x devices SYNOPSIS
/usr/ucb/ucblinks [-e rulebase] [-r rootdir] DESCRIPTION
ucblinks creates symbolic links under the /dev directory for devices whose SunOS 5.x names differ from their SunOS 4.x names. Where possi- ble, these symbolic links point to the device's SunOS 5.x name rather than to the actual /devices entry. ucblinks does not remove unneeded compatibility links; these must be removed by hand. ucblinks should be called each time the system is reconfiguration-booted, after any new SunOS 5.x links that are needed have been created, since the reconfiguration may have resulted in more compatibility names being needed. In releases prior to SunOS 5.4, ucblinks used a nawk rule-base to construct the SunOS 4.x compatible names. ucblinks no longer uses nawk for the default operation, although nawk rule-bases can still be specifed with the -e option. The nawk rule-base equivalent to the SunOS 5.4 default operation can be found in /usr/ucblib/ucblinks.awk. OPTIONS
-e rulebase Specify rulebase as the file containing nawk(1) pattern-action statements. -r rootdir Specify rootdir as the directory under which dev and devices will be found, rather than the standard root directory /. FILES
/usr/ucblib/ucblinks.awk sample rule-base for compatibility links ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
devlinks(1M), disks(1M), ports(1M), tapes(1M), attributes(5) SunOS 5.10 13 Apr 1994 ucblinks(1B)
All times are GMT -4. The time now is 02:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy