03-17-2006
You could use Perl's unpack() to read fixed length field records.
e.g. put something like this in a file and have it run through Perl
<pre>
$ cat insert_pipes.pl
#!/usr/bin/perl
while (<DATA>) {
chomp;
@unpacked = unpack 'A1A3A8A8A5A9x1A*', $_;
print join('|', @unpacked[0..5], q{ }, $unpacked[-1], q{}), "\n";
}
__DATA__
B065200512312004123111010000061451 000021853
B065200512312004123111020000621907 000417802
B065200512312004123111030000005214 000005861
B065200512312004123111040000120133 000088448
$ ./insert_pipes.pl
B|065|20051231|20041231|11010|000061451| |000021853|
B|065|20051231|20041231|11020|000621907| |000417802|
B|065|20051231|20041231|11030|000005214| |000005861|
B|065|20051231|20041231|11040|000120133| |000088448|
</pre>
N.B. to moderators,
How do I enable markup recognition in this forum?
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
hi,
i have a flat file, with lines (records), and fields, and each field is separated by pipe ( | ) :
1|078|012006|3,9
2|078|012006|8692275|4|2|GON3507090
2|078|012006|7655734|9|0|GON3507090
2|078|012006|7572405|5|4|GCR5N07090
what i need is to insert a pipe in the end of the line:... (3 Replies)
Discussion started by: DebianJ
3 Replies
2. Shell Programming and Scripting
Hi All :),
I am very new to unix. I am requiring ur help in developing shell script for below problem.
I have to replace the second field of file with values of array sequentially where first field is ValidateKeepVar
<File>
UT-ExtractField 1 | &LogEntry &Keep(DatatoValidate)... (3 Replies)
Discussion started by: rohiiit.sharma
3 Replies
3. Shell Programming and Scripting
Enclosed is comma separated text file. I need to write a korn shell program that will parse the text file and insert the values into Oracle database.
I need to write the korn shell program on Red Hat Enterprise Linux server.
Oracle database is 10g. (15 Replies)
Discussion started by: shellguy
15 Replies
4. Shell Programming and Scripting
Hi All,
I need a shell script which could insert a sequence number column inside a dat file(pipe delimited).
I have the dat file similar to the one as shown below..
|A|B|C||D|E
|F|G|H||I|J
|K|L|M||N|O
|P|Q|R||S|T
As shown above, the column 4 is currently blank and i need to insert sequence... (5 Replies)
Discussion started by: nithins007
5 Replies
5. Shell Programming and Scripting
this is Korn shell unix.
The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies
6. Shell Programming and Scripting
Hey guys, i have a file a.txt and i need to insert a dummy data into it as per the below pattern..
bash: cat a.txt
1234,34
3434,45
4545,56
3434,56
Now i need the file in the below pattern
1234,34,a0001,C_01
3434,45,a0002,C_02
4545,56,a0003,C_03
3434,56,a0004,C_04
here the count of... (3 Replies)
Discussion started by: jaituteja
3 Replies
7. Shell Programming and Scripting
Hi,
I am trying to find the lines in a pipe delimited file where 11th column has not null values. Any help is appreciated. Need help asap please.
thanks in advance. (3 Replies)
Discussion started by: manikms
3 Replies
8. Shell Programming and Scripting
Hi All ,
I have pipe delimiter file with 11 columns . I need to insert 4 empty columns after column 10 . and After 11 column I need to insert a column which is having the same value for all the rows .
My file
1|2|3|4|5|6|7|8|9|10|11
New file
... (11 Replies)
Discussion started by: Hypesslearner
11 Replies
9. Shell Programming and Scripting
Hi
The file contains 12 months of date and less than 12 months of data I want to display if date filed less than 12 months of data I want to insert a value amount 1 to amount4 0 and dates as well.
12345|Date|cntry|amount1|amount2|amount3|amoun4... (2 Replies)
Discussion started by: jagu
2 Replies
10. Shell Programming and Scripting
I am trying to use awk to find all the $3 values in file2 that are between $2 and $3 in file1. If a value in $3 of file2 is between the file1 fields then it is printed along with the $6 value in file1. Both file1 and file2 are tab-delimited as well as the desired output. If there is nothing to... (4 Replies)
Discussion started by: cmccabe
4 Replies