Sponsored Content
Full Discussion: Split BIG report using nawk
Top Forums UNIX for Dummies Questions & Answers Split BIG report using nawk Post 302161029 by raychu65 on Wednesday 23rd of January 2008 11:24:39 AM
Old 01-23-2008
Data Split BIG report using nawk

I have the following nawk script:

nawk -F: '{ if($0 ~ "^Report No") {fl=1; i=0;}
if(fl==1){data[i]=$0; i++}
if($0 ~ "^BE NO:")
{
fname = "reprot_"$2".lis";
gsub(" ","",fname);
for(j=0;j<i;j++) print data[j] > fname;
fl=0;
}
else if(fl==0) print $0 > fname;
}' filename


When I try to apply it to split the big reports into smaller report, that is work fine. (the big report is start with "Report No" at the very begining)

However when I try to apply it to split the big report, that big report is start with few blank lines. I got the following error:

nawk: null file name in print or getline
input record number 1
source line number 9


The big report file is like the following (report.lis)
LINE # Report_code
1
2
3
4
5 Report No.: AAA
6
7 BE NO: 111
8
9 asfsdflsjdfklsdjfklsjfklsfsflsjdlk
10 fsdfjsfkjsklfsfj
11
12
13
14
15 Report No.: AAA
16
17 BE NO: 111
18
19 sdfsdfjsdklfjsfkj
20 fsdflkjsdfklsjkl
21
22
23
24
25 Report No.: AAA
26
27 BE NO: 222
28
29 dadaskdhasdjkd
30 dashdjkashdjhajkh
31
32
33
34
35 Report No.: AAA
36
37 BE NO: 222
38
39 dasdjaklsdjkladjkla
40 daskdjaskldjakldjklaj
41
42
43
44
45 Report No.: AAA
46
47 BE NO: 333
48
49 ddasdjaskldjkladjklasj
50 daskdjaskldjaskldj
51
52
53
54
55 Report No.: AAA
56
57 BE NO: 333
58
59 djakdadjaklsjdjak
60 dakdjakljdklajklsd
61
62
63
64
65 .................
66 .................
67 .................

my expected report result is like the following:
report_111.LIS
1
2
3
4
5 Report No.: AAA
6
7 BE NO: 111
8
9 asfsdflsjdfklsdjfklsjfklsfsflsjdlk
10 fsdfjsfkjsklfsfj
11
12
13
14
15 Report No.: AAA
16
17 BE NO: 111
18
19 sdfsdfjsdklfjsfkj
20 fsdflkjsdfklsjkl

report_222.LIS
21
22
23
24
25 Report No.: AAA
26
27 BE NO: 222
28
29 dadaskdhasdjkd
30 dashdjkashdjhajkh
31
32
33
34
35 Report No.: AAA
36
37 BE NO: 222
38
39 dasdjaklsdjkladjkla
40 daskdjaskldjakldjklaj

report_333.LIS
41
42
43
44
45 Report No.: AAA
46
47 BE NO: 333
48
49 ddasdjaskldjkladjklasj
50 daskdjaskldjaskldj
51
52
53
54
55 Report No.: AAA
56
57 BE NO: 333
58
59 djakdadjaklsjdjak
60 dakdjakljdklajklsd

Please help me, since I am a new baby in the Unix Script.....
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Nawk Split

Hello. I have a input file in this format: line1data :: line1data :: line1data line2data :: line2data :: line2data I would like to split each lines data element into an array: array1=line1data array1=line1data array1=line1data array2=line2data array2=line2data array2=line2data I... (3 Replies)
Discussion started by: steveramsey
3 Replies

2. Shell Programming and Scripting

Split a Big Report.

Hi All, I am a newbie for Unix Script. I have report like the following: (file name: Report.txt): Report No.: AAA BE NO: 111 asfsdflsjdfklsdjfklsjfklsfsflsjdlk fsdfjsfkjsklfsfj Report No.: AAA BE NO: 111 sdfsdfjsdklfjsfkj fsdflkjsdfklsjkl Report No.: AAA (16 Replies)
Discussion started by: raychu65
16 Replies

3. Shell Programming and Scripting

Help Needed : Split one big file to multiple files

Hi friends, I have data in flat file as following, first filed is the customer number. We have almost 50-100 customers in the system 100 ABC A123 100 BVC D234 100 BNC N324 200 CBC A122 200 AVC D294 200 HNC N324 300 GBC A173 300 FVC D234 300 DNC N344 I want to split the file and... (5 Replies)
Discussion started by: monicasgupta
5 Replies

4. UNIX for Advanced & Expert Users

Split a big file into two others files

Hello, i have a very big file that has more then 80 MBytes (100MBytes). So with my CVS Application I cannot commit this file (too Big) because it must have < 80 MBytes. How can I split this file into two others files, i think the AIX Unix command : split -b can do that, buit how is the right... (2 Replies)
Discussion started by: steiner
2 Replies

5. Shell Programming and Scripting

Need to Split Big XML into multiple xmls

Hi friends.. We have urgent requirement.We need to split the big xml having multiple orders into multiple xmls having each order in each xml. For Example In input XMl will be in following format with multiple line orders.. <OrderDetail BillToKey="20100805337" Createuserid="CreateGuestOrder"... (8 Replies)
Discussion started by: dprakash
8 Replies

6. Shell Programming and Scripting

NAWK: changing string-format with split

Hi all, I try to make a awk-script, which counts lines, summarized by pdf and xml. So far it works, but for sorting reasons, I'd like to change the format from the field $1 from dd-mm-yyyy to yyyy-mm-dd. This works find, but: split() and sprintf() prints its output (for no reason, the results... (2 Replies)
Discussion started by: regisl67
2 Replies

7. HP-UX

How to split big file on HP-UX and join on Windows?

Hi HP-admins, I have 120GB file on HP-UX and need to split to 4GB pieces and join them on Windows. As I don't want to use zipsplit, tried to use split command and join on windows using "copy /b" but it doesn't work (It merges and creates new file but file is corrupt) What is the correct... (6 Replies)
Discussion started by: prvnrk
6 Replies

8. Shell Programming and Scripting

Split a big file into multiple files using awk

this thread is a continuation from previous thread https://www.unix.com/shell-programming-and-scripting/223901-split-big-file-into-multiple-files-based-first-four-characters.html ..I am using awk to split file and I have a syntax error while executing the below code I am using AIX 7.2... (4 Replies)
Discussion started by: etldev
4 Replies

9. Shell Programming and Scripting

Split Big XML file Base on tag

HI I want to split file base on tag name. I have few header and footer on file <?xml version="1.33" encing="UTF-8"?> <bulkCmConfigDataFile" <xn:SubNetwork id="ONRM_ROOT"> <xn:MeContext id="PPP04156"> ... (4 Replies)
Discussion started by: pareshkp
4 Replies

10. Solaris

Split a big file system to several files

Gents Actually I have question and i need your support. I have this NAS file system mounted as /coresys has size of 7 TB I need to Split this file system into several file systems as mount points I mean how to can I Split it professionally to different NAS mount points how to can I decide... (2 Replies)
Discussion started by: AbuAliiiiiiiiii
2 Replies
GRDINFO(l)																GRDINFO(l)

NAME
grdinfo - Get information about the contents of a 2-D grd file SYNOPSIS
grdinfo grdfiles [ -C ] [ -D ] [ -F ] [ -L1 ] [ -L2 ] [ -M ] [ -V ] DESCRIPTION
grdinfo reads a 2-D binary grd file and reports various statistics for the (x,y,z) data in the grdfile. The output information contains the minimum/maximum values for x, y, and z, where the min/max of z occur, the x- and y-increments, and the number of x and y nodes, and [optionally] the mean, standard deviation, and/or the median, L1 scale of z, and number of nodes set to NaN. grdfile The name of one or several 2-D grd files. OPTIONS
No space between the option flag and the associated arguments. -C Formats the report using tab-separated fields on a single line. The output is w e s n z0 z1 dx dy nx ny [ x0 y0 x1 y1 ] [ med scale ] [ mean std rms] [n_nan]. The data in brackets are output only if the corresponding options -M, -L1, -L2, and -M are used, respec- tively. -D Report grid domain and x/y-increments using dd:mm:ss[.fff] notation [Default is decimal]. Does not apply to the -C option. -F Report grid domain and x/y-increments world mapping format [Default is generic]. Does not apply to the -C option. -L1 Report median and L1 scale of z (L1 scale = 1.4826 * Median Absolute Deviation (MAD)). -L2 Report mean and standard deviation of z. -M Find and report the location of min/max z-values, and count and report the number of nodes set to NaN, if any. -V Selects verbose mode, which will send progress reports to stderr [Default runs "silently"]. EXAMPLES
To obtain all the information about the data set in file hawaii_topo.grd, try grdinfo -L1 -L2 -M hawaii_topo.grd SEE ALSO
gmt(1gmt), grd2cpt(1gmt), grd2xyz(1gmt), grdedit(1gmt) 1 Jan 2004 GRDINFO(l)
All times are GMT -4. The time now is 11:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy