Split one file to Multiple file with report basis in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split one file to Multiple file with report basis in unix
# 8  
Old 02-06-2011
Hi DG,

The Follwoing script is working fine...But i want one more result..

If same header again comming in the inputfile, then append in the previous output(report) file.
like: compare 1 and 3 only compare...
Code:
%sAEGONCA| |MUMBAI | :EXPC|N|D - Report1.txt
%sAGENTCA| |MUMBAI | :EXPC|Y|D - 2nd times it will come it is going to Report1.txt

Code:
awk '/%s/{f=0 ;n++; print >(file="Report" n); close("Report" n-1)} f{ print > file}; /%s/{f=1}'  1102010004.CLT

Please help

Moderator's Comments:
Mod Comment Please start using code tags. Thank you.

Last edited by Scott; 02-06-2011 at 10:55 AM..
# 9  
Old 02-07-2011
Well, consider the merge to be another task, rather than cluttering the process that works. The only thing you might need is keys, which might go into the file name. Then, you can process the file names in key sorted sequence and for adjacent names, combine files with identical keys as the prior name.
Code:
 
#!/usr/bin/ksh
 
oldKey= oldFile=
 
ls |sort -t|while read f
do
  if [ "$oldKey" != "${f#*.}" ]
  then
   oldKey="${f#*.}"
   oldFile=all.$oldKey
   >$oldFile  # truncate file
  fi
 
  cat $f >>$oldFile
done

This User Gave Thanks to DGPickett For This Post:
# 10  
Old 02-07-2011
Please try:

Code:
awk -v RS="%s" 'NR==FNR && NR!=1{a[$1]=a[$1]"%s"$0}END{for(i in a) print "%s"a[i] >"MUMBAI000"++x".txt"}'  urfile

This User Gave Thanks to yinyuemi For This Post:
# 11  
Old 02-09-2011
Thanks Both are working fine...great...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split into multiple files by using Unique columns in a UNIX file

I have requirement to split below file (sample.csv) into multiple files by using the unique columns (first 3 are unique columns) sample.csv 123|22|56789|ABCDEF|12AB34|2019-07-10|2019-07-10|443.3400|1|1 123|12|5679|BCDEFG|34CD56|2019-07-10|2019-07-10|896.7200|1|2... (3 Replies)
Discussion started by: RVSP
3 Replies

2. UNIX for Beginners Questions & Answers

Split large file into 24 small files on one hour basis

I Have a large file with 24hrs log in the below format.i need to split the large file in to 24 small files on one hour based.i.e ex:from 09:55 to 10:55,10:55-11:55 can any one help me on this.! ... (20 Replies)
Discussion started by: Raghuram717
20 Replies

3. UNIX for Beginners Questions & Answers

Split a txt file on the basis of line number

I have to split a file containing 100 lines to 5 files say from lines ,1-20 ,21-30 ,31-40 ,51-60 ,61-100 Here is i can do it for 2 file but how to handle it for more than 2 files awk 'NR < 21{ print >> "a"; next } {print >> "b" }' $input_file Please advidse. Thanks (4 Replies)
Discussion started by: abhaydas
4 Replies

4. Linux

Split a large textfile (one file) into multiple file to base on ^L

Hi, Anyone can help, I have a large textfile (one file), and I need to split into multiple file to break each file into ^L. My textfile ========== abc company abc address abc contact ^L my company my address my contact my skills ^L your company your address ========== (3 Replies)
Discussion started by: fspalero
3 Replies

5. Shell Programming and Scripting

Splitting XML file on basis of line number into multiple file

Hi All, I have more than half million lines of XML file , wanted to split in four files in a such a way that top 7 lines should be present in each file on top and bottom line of should be present in each file at bottom. from the 8th line actual record starts and each record contains 15 lines... (14 Replies)
Discussion started by: ajju
14 Replies

6. Shell Programming and Scripting

How to split file into multiple files using awk based on 1 field in the file?

Good day all I need some helps, say that I have data like below, each field separated by a tab DATE NAME ADDRESS 15/7/2012 LX a.b.c 15/7/2012 LX1 a.b.c 16/7/2012 AB a.b.c 16/7/2012 AB2 a.b.c 15/7/2012 LX2 a.b.c... (2 Replies)
Discussion started by: alexyyw
2 Replies

7. Shell Programming and Scripting

Split a file into multiple files based on first two digits of file.

Hi , I do have a fixedwidth flatfile that has data for 10 different datasets each identified by the first two digits in the flatfile. 01 in the first two digit position refers to Set A 02 in the first two digit position refers to Set B and so on I want to genrate 10 different files from my... (6 Replies)
Discussion started by: okkadu
6 Replies

8. Shell Programming and Scripting

Split file in unix into multiple files

Hi Gurus I have to split the incoming source file into multiple file. File contains some unwanted XML tags also . Files looks like some XML tags FILEHEADERABC 12 -- --- ---- EOF some xml tags xxxFILEHEADERABC 13 -- --- ---- EOF I have to ignore XML tags and only split file... (6 Replies)
Discussion started by: manish2608
6 Replies

9. Shell Programming and Scripting

Help with split one file content into multiple different file

Input file: cat input_file.txt data_1 2342 data_3 242 data_1 3546 data_5 458 data_10 342 data_30 42 data_10 346 content_50 48 content_1 2343 Desired output: cat output_file1.txt data_1 2342 data_3 242 data_1 3546 data_5 458 (2 Replies)
Discussion started by: perl_beginner
2 Replies

10. Shell Programming and Scripting

Help with split the file content into multiple different file

Input file content: NA_10001 XA_10081 NG_10015 AC_1321.1 . . Desired output file: ls *.txt NA_10001.txt XA_10081.txt NG_10015.txt AC_1321.1.txt cat NA_10001.txt NA_10001 cat XA_10081.txt XA_10081 (1 Reply)
Discussion started by: perl_beginner
1 Replies
Login or Register to Ask a Question