awk multiple file reformatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk multiple file reformatting
# 1  
Old 01-18-2011
Java awk multiple file reformatting

I hopefully have a simple request - I need to process multiple files reformatting the output based on tags at the beginning of each line. So the data for the new 3 lines of the output file are in the HDR line and then the details are in the DTL tagged lines.

Code:
 
for ifile in $indir
do
echo Processing Inbound Orders file:- $ifile
#Begin Code
awk 'NR==1 {print "HEADER    " substr($0,11,13) "              " substr($0,24,47) "                                      " substr($0,61,50) "\n" \
                 "BUYER    ", substr($0,73,30) "\n" \
                 "SHIPTO   ", substr($0,103,30)} 
          {print "DETAIL   ",substr($0,11,167)}' $ifile >> $ofile
done

The code that I have so far works, to a point, but I am getting the DETAIL section repeating after SHIPTO before the code moves on to the next line of the file.

Quote:
Input File:-
HDR CUSTID ORDERNO PO_NUMBER BUYER_NAME SHIP_TO NAME
DTL 1 ITEMID_1 1
DTL 2 ITEMID_2 1
DTL 3 ITEMID_3 2
DTL 4 ITEMID_4 2
Quote:
Current Output File:-
HEADER CUSTID ORDERNO PO_NUMBER
BUYER BUYER_NAME
SHIPTO SHIP_TO NAME
DETAIL CUSTID ORDERNO PO_NUMBER BUYER_NAME SHIP_TO NAME
DETAIL 1 ITEMID_1 1
DETAIL 2 ITEMID_2 1
DETAIL 3 ITEMID_3 2
DETAIL 4 ITEMID_4 2
Many thanks in advance for your help!
# 2  
Old 01-18-2011
Try:
Code:
                 "SHIPTO   ", substr($0,103,30);next}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reformatting of an output file

Hi, i've got the following output file: 170724_1600 | SYSTEM | 449 | 282 | 167 | 62 170724_1600 | CCS_SCP_DATA | 200 | 88 | 112 | 44 170724_1600 | CCS_SCP_SUBS_I | 2001 | 1751 | 250 | 87 170724_1600 | UIS_CDR_INDEX | 2001 | 1 | 2000 | 0 170724_1600 | LCP_INDEX | 200 | 5 | 195 | 2... (4 Replies)
Discussion started by: nms
4 Replies

2. UNIX for Dummies Questions & Answers

Help reformatting input file

Hi, I have an input file that looks like this (columns are tab delimited: Data000005-RA GO:0003735 GO:0005840 GO:0006412 Data000005-RA GO:0003735 Data000009-RA GO:0003735 GO:0005622 GO:0005840 GO:0006412 ... (2 Replies)
Discussion started by: Fahmida
2 Replies

3. Shell Programming and Scripting

Reformatting a file for biological purpose

Dear ALL, I would really appreciate if you could help me in reformatting a file in this way: The file refers to a list of genetic coordinates, each lines has a score value and the associated chromosome is listed in the line starting with chrom . If more coordinates are found, the start... (2 Replies)
Discussion started by: paolo.kunder
2 Replies

4. Shell Programming and Scripting

awk help reformatting badly formatted time field

I need help reformatting an input file with spaces in the time field (4th field). I want the field to look like “hh:mm” with appropriate embedded zeros, but instead it has “h :m “ if the hour and/or minute are single character. I'm pretty new to scripting and this is beyond me. Any help would... (4 Replies)
Discussion started by: lisep
4 Replies

5. Shell Programming and Scripting

Awk match multiple columns in multiple lines in single file

Hi, Input 7488 7389 chr1.fa chr1.fa 3546 9887 chr5.fa chr9.fa 7387 7898 chrX.fa chr3.fa 7488 7389 chr21.fa chr3.fa 7488 7389 chr1.fa chr1.fa 3546 9887 chr9.fa chr5.fa 7898 7387 chrX.fa chr3.fa Desired Output 7488 7389 chr1.fa chr1.fa 2 3546 9887 chr5.fa chr9.fa 2... (2 Replies)
Discussion started by: jacobs.smith
2 Replies

6. Shell Programming and Scripting

Stripping characters from a file and reformatting according to another one

Dear experts, my problem is pretty tricky. I want to change a file (see attached input.txt), according to another file (help.txt). The output that is desired is in output.txt. The example is attached. Note that -dashes should not be treated specially, they are considered normal characters,... (2 Replies)
Discussion started by: TheTransporter
2 Replies

7. Shell Programming and Scripting

Help for reformatting text file and creating new format

Hi all, I have an input file like 1,date,company,, 1,date,comapny,, 2,000,,,567,ACT,00,,,,KKG,M1,D45,,67J,+4500000000 2,000,,,567,ACT,00,,,,KKG,M6,D49,,56J,+6000 2,000,,,567,ACT,00,,7,,KKG,M3,D58,,68h,-70000 2,000,,,567,ACT,00,,,,KKG,M9,D95,,34m,0.00 3,total what i require is 1.I... (2 Replies)
Discussion started by: selvankj
2 Replies

8. Shell Programming and Scripting

reformatting xml file, sed or awk I think (possibly perl)

I have some xml files that cannot be read using a standard parser, or I am using the wrong parser. The issues seems to be spaces in some of the tags. Here is a sample,<UgUn 2 > <Un> -0.426753 </Un> </UgUn>The parser isn't able to find the number 2, so that information is lost, etc. It seems... (16 Replies)
Discussion started by: LMHmedchem
16 Replies

9. Shell Programming and Scripting

Reformatting Data in AWK

Dear AWK Users, I have a data set that is so large (Gigabytes) that it cannot be opened in the vi editor in its entirety. But I can manipulate the entire thing in AWK. It is formatted in a regular manner such that it has the variable descriptions or listings preceeding the variables. The latter... (13 Replies)
Discussion started by: sda_rr
13 Replies

10. UNIX for Dummies Questions & Answers

Reformatting file

Hi, How can I reformat a file (text file) using unix command. This file was FTP'd from Mainframe and contains some garbage character at the end of each line. Each line contains special characters '<soh>' at the end which should have been spaces when I view it in emacs or nedit. I couldnt do find... (2 Replies)
Discussion started by: mrjunsy
2 Replies
Login or Register to Ask a Question