Sponsored Content
Full Discussion: Format using AWK
Top Forums Shell Programming and Scripting Format using AWK Post 302565754 by Corona688 on Tuesday 18th of October 2011 04:03:38 PM
Old 10-18-2011
If you have nawk or gawk:

Code:
$ cat frag.awk

BEGIN { OFS="," }

/^IMAGE/ && I {
        for(N=1; N<=3; N++)
        {
                S="";   P=""
                for(K in FRAG)
                {
                        split(K, IND, SUBSEP);
                        if(IND[1] == N)
                        {
                                S=S P FRAG[K];
                                delete FRAG[K];
                                P=":"
                        }
                }
                F[N]=S;
        }

        print A[0], A[1], A[2], A[3], A[4], A[5], F[1], F[2], F[3];
}

/^IMAGE/ {
        A[0]=$2;
        A[1]=$6;
        A[2]=$7;
        A[3]=$11;
        A[4]=$14;
        A[5]=$16;
        I=1
        }

/^FRAG/ {       FRAG[$2, $9]=$9 "(" $10 ")"     }
END {

        for(N=1; N<=3; N++)
        {
                S="";   P=""
                for(K in FRAG)
                {
                        split(K, IND, SUBSEP);
                        if(IND[1] == N)
                        {
                                S=S P FRAG[K];
                                delete FRAG[K];
                                P=":"
                        }
                }
                F[N]=S;
        }

        print A[0], A[1], A[2], A[3], A[4], A[5], F[1], F[2], F[3];
}

$ gawk -f frag.awk < data

ap00m43,ap00m43_1318914034,UNIX_STANDARD_ADC_2,Daily,1318914034,1319518834,G12002(ts00p71):G11890(ts00p71),,
db00p01c,db00p01c_1167540253,UNIX_ORAPROD_1,ORACLE_5YEARS_ARCH,1167540253,1325220253,D09714(ts00p22),D07775(ts00p21),

$

This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

data format from (4.56 0.7) -> 4.6(7) awk?!

Hi, I have to manipulate a data file which say reads like this {$index $value $error_on_value} aa 4.56 0.7 bb 123.456 0.00987 cc 987654 321 . . in easily human readable format of type aa 4.6(7) bb 123.456(1) cc 9.877(3)e+05 value rounded to 4.6 with error of 0.7 on the last... (4 Replies)
Discussion started by: ahan
4 Replies

2. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

3. Shell Programming and Scripting

How to format columns using AWK

Hi, How to format something like this: John Roberts 324-141-984 Acct Jack Williams 159-555-555 Acct William Jackson 949-911-888 Acct Mark J Walton 145-852-252 Acct Fred P Milton 483-244-390 Acct Bill P J Miller 404-050-223 Acct into... (12 Replies)
Discussion started by: ora_umair
12 Replies

4. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

5. Shell Programming and Scripting

awk:How to format a number?

Hello, I need to format a number..like 12900 should be printed as 12,900 and 1209 as 1,209 and so on. (Just like we do in excel). Can this be done in awk. any printf options we have?Please suggest me. Thanks! (8 Replies)
Discussion started by: vijay_0209
8 Replies

6. Shell Programming and Scripting

Format in AWK please

Am new to AWk, Can anyone help me to get excepected output from given input please. input file student: name details of them = details_needed class: 5th_needed adress: address_needed Expected output: details of them = 5th_needed = address_needed ---------- Post updated at... (5 Replies)
Discussion started by: Elavarasan
5 Replies

7. Shell Programming and Scripting

awk Format

Guys ,, pls .. need help with this ... File 1 0A6C Not Visible ???:? NA:NA TDEV N/Grp'd NR 5121 0A6D Not Visible ***:* NA:NA TDEV N/Grp'd RW 33784 0A6E Not Visible ***:* NA:NA TDEV N/Grp'd RW 33784... (4 Replies)
Discussion started by: greycells
4 Replies

8. UNIX for Dummies Questions & Answers

Solaris8 = How to format this df -k | awk

Hi, Unfortunately, we still have Solaris 8 to support and it does not support df -h so I am stucked with having to use df -k. UNIX shell is ksh. Example of df -k run is below: $ df -k /db/test01 | awk '{ print }' Filesystem kbytes used avail capacity Mounted on... (2 Replies)
Discussion started by: newbie_01
2 Replies

9. Shell Programming and Scripting

Format a file using awk

I have a file as below empty May7 noread May8 How can process this file and print as below. neat and clean. Filename Date Created empty May7 noread May8 I tried something with printf before creating the file itself... (3 Replies)
Discussion started by: Tuxidow
3 Replies

10. Shell Programming and Scripting

awk incorrect format

I was wondering whether anyone has any idea what is happening here. I'm using simple code to compare 2 tab delimited files based on column 1 values. If the column1 value of file1 exists in file2, then I'm to print the column4 value in file2 in column3 of file1. Here is my code: 1st I have to... (6 Replies)
Discussion started by: Geneanalyst
6 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 04:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy