Inside that file at postion 21 and length 1 of each line we have record type indicator like C,D,B,E
I'm trying to create on unix program which will check the record type indicator and store in different file
So here all records with record type indicator as 'C' will should be store in file C.txt and similar to other record type.
Script should supply position and length as arguments
I tried below code and seems its not good and not working too
Please help
Regards
Ibrar Ahmad
Moderator's Comments:
Please use CODE tags (not ICODE tags) for multi-line sample input, output, and code segments.
Last edited by Don Cragun; 05-06-2015 at 04:31 AM..
Reason: Change ICODE tags to CODE tags.
How many different output files (maximum) will need to be created from a single input file? (If the answer is no more than nine, the solution is much simpler and faster on many systems.)
What operating system are you using? And, what version(s) of awk are available?
Your approach is a bit overcomplicated and suboptimal. Why use all those for loops to extract and sort when finally all data end up in some few text files? Why use shell builtins and awk in parallel (a new awk process is created rectype x lines times! Each overwriting FILE_$REC)? Decide what to use, and the result will be a simple one liner.
You can't use shell variables in an awk script; although, awk has mechanisms to pass values to internal variables. See man awk.
Your new awk is way better than what you did in post#1, but still has some potential.
Try
or
If chances are there will be > 9 (or any largest open file count) output files, you'll need to close them after each print and use >> for an append operation in awk.
hdr=$(cut -c1 $path$file|head -1)#extract header”H”
trl=$(cut -c|path$file|tail -1)#extract trailer “T”
SplitFile=$(cut -c 50-250 $path 1$newfile |sed'$/ *$//' head -1')# to trim white space and extract table name
If; then # start loop if it is a header
While read I #read file
Do... (4 Replies)
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)
Hi All,
I am new to Scripting language.
I want to split a file and create several subfiles using Perl script.
Example :
File format :
Sourcename ID Date Nbr
SU IMYFDJ 9/17/2012 5552159976555
SU BWZMIG 9/14/2012 1952257857887
AR PEHQDF 11/26/2012 ... (13 Replies)
I m writing a script to check Server Hardening.
The problem is whenever i add new point it grows and it become very tedious to edit the script file.
Is there any way of making them separate and call them from one base script?
Is it possible to define global variable that can be accessed via... (5 Replies)
Can anyone help me in giving a script for the below scenario
I have file from the source increamenting in size...
I require to write a script witch will move the data to the new file once the file reaches 50MB of size .
This needs If the first file reaches 50MB then my script has to generate... (3 Replies)
Hello All,
I have a small problem with file group/splitting and I am trying to get the best way to perform this in unix. I am trying with awk but need some suggestion what would be the best and fastest way to-do it.
Here is the problem. I have a fixed length file with filled with product... (4 Replies)
Hi,
I need to split the file lines in below format as.
Input file : Sample.txt
<Rule expression="DeliverToCompID IS NULL" invert="true">
<Rule field="PossDupFlag" value="Y" >
<Rule expression="OrdStatus = '2' AND OrigClOrdID IS NULL">
Output... (5 Replies)