Sponsored Content
Top Forums Shell Programming and Scripting Execution of loop :Splitting a single file into multiple .dat file Post 302911939 by RudiC on Monday 4th of August 2014 04:53:11 PM
Old 08-04-2014
Your file names don't match the strings in the sample file. Try
Code:
awk '$1=="H" {FN=substr($5, 1, index($5," ")-1)} {print > FN}' FS="|" file
cf FIL*
FILE1.DAT:
H|123|45555|4555|FILE1.DAT   WHITE SPACE   |33|444
D|123|45555|4555|45T55|33|444
D|FF|676|YTYYU|878
T|GFG|GFGF|7879|
FILE2.DAT:
H|123|45555|4555|FILE2.DAT   WHITE SPACE   |33|444
D|123|45555|4555|45T55|33|444
D|FF|676|YTYYU|878
T|GFG|GFGF|7879|
FILE3.DAT:
H|123|45555|4555|FILE3.DAT   WHITE SPACE   |33|444
D|123|45555|4555|45T55|33|444
D|FF|676|YTYYU|878
T|GFG|GFGF|7879|3434

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting a single line into multiple lines

I have a case where, I need to look into a file. Go to each line of the file, find the length of the line, if the length of the line is more than 75 chars, I need to split the line into multiple lines of 75chars max. If the length of the line is less than 75, we need not do anything. So at the... (4 Replies)
Discussion started by: thanuman
4 Replies

2. UNIX for Advanced & Expert Users

Splitting the single csv file

Hi, I have a requiement where in i will get a single file but there will be mutiple headers. Suppose say for eg: Header1 Data... Data... Header2 Data.. Data.. Header3 Data.. Data.. I want to split each with the corresponding data into a single file. Please let me know how... (1 Reply)
Discussion started by: weknowd
1 Replies

3. Shell Programming and Scripting

Splitting & reformating a single file

I have a bif text file with the following format: d1_03 fr:23 d1_03 fr:56 d1_03 fr:67 d1_03 fr:78 d1_01 fr:35 d1_01 fr:29 d1_01 fr:45 d2_09 fr:34 d2_09 fr:78 d3_98 fr:90 d3_98 fr:104 d3_98 fr:360 I have like thousands of such lines I want to reformat this file based on column 1... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

4. Shell Programming and Scripting

Splitting single file into n files

Hi all, I am new to scripting and I have a requirement we have source file as HEADER 01.10.2010 14:32:37 NAYA TA0022 TA0000 20000001;20060612;99991231;K4;02;3 20000008;20080624;99991231;K4;02;3 20000026;19840724;99991231;KK;01;3 20000027;19840724;99991231;KK;01;3... (6 Replies)
Discussion started by: srk409
6 Replies

5. Shell Programming and Scripting

Splitting a file in to multiple files and passing each individual file to a command

I have an input file with contents like: MainFile.dat: 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 12247689|7896|77698080 16768900|hh78|78959390 ... (4 Replies)
Discussion started by: rkrish
4 Replies

6. Shell Programming and Scripting

Need help splitting huge single record file

I was given a data file that I need to split into multiple lines/records based on a key word. The problem is that it is 2.5GB or bigger and everything I try in perl or sed causes a Segmentation fault. Can someone give me some other ideas. The data is of the form:... (5 Replies)
Discussion started by: leolson
5 Replies

7. 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

8. Shell Programming and Scripting

Splitting a single file to multiple files

Hi Friends , Please guide me with the code to extract multiple files from one file . The File Looks like ( Suppose a file has 2 tables list ,column length may vary ) H..- > File Header.... H....- >Table 1 Header.... D....- > Table 1 Data.... T....- >Table 1 Trailer.... H..-> Table 2... (1 Reply)
Discussion started by: AspiringD
1 Replies

9. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

10. UNIX for Beginners Questions & Answers

Output file name and file contents of multiple files to a single file

I am trying to consolidate multiple information files (<hostname>.Linux.nfslist) into one file so that I can import it into Excel. I can get the file contents with cat *Linux.nfslist >> nfslist.txt. I need each line prefaced with the hostname. I am unsure how to do this. --- Post updated at... (5 Replies)
Discussion started by: Kentlee65
5 Replies
Quote(3pm)						User Contributed Perl Documentation						Quote(3pm)

NAME
XML::Quote - XML quote/dequote functions SYNOPSIS
use strict; use XML::Quote qw(:all); my $str=q{666 > 444 & "apple" < 'earth'}; print xml_quote($str)," "; # 666 &gt; 444 &amp; &quot;apple&quot; &lt; &apos;earth&apos; my $str2=q{666 &gt; 444 &amp; &quot;apple&quot; &lt; &apos;earth&apos;}; print xml_dequote($str2)," "; # 666 > 444 & "apple" < 'earth' my $str3=q{666 > 444 & "apple" < 'earth'}; print xml_quote_min($str3)," "; # 666 > 444 &amp; &quot;apple&quot; &lt; 'earth' DESCRIPTION
This module provides functions to quote/dequote strings in "xml"-way. All functions are written in XS and are very fast; they correctly process utf8, tied, overloaded variables and all the rest of perl "magic". FUNCTIONS
$quoted = xml_quote($str); This function replaces all occurences of symbols '&', '"', ''', '>', '<' to '&amp;', '&quot;', '&apos;', '&gt;', '&lt;' respectively. Returns quoted string or undef if $str is undef. $dequoted = xml_dequote($str); This function replaces all occurences of '&amp;', '&quot;', '&apos;', '&gt;', '&lt;' to '&', '"', ''', '>', '<' respectively. All other entities (for example &nbsp;) will not be touched. Returns dequoted string or undef if $str is undef. $quoted = xml_quote_min($str); This function replaces all occurences of symbols '&', '"', '<' to '&amp;', '&quot;', '&lt;' respectively. Symbols ''' and '>' are not replaced. Returns quoted string or undef if $str is undef. EXPORT
xml_quote(), xml_dequote() are exported as default. PERFORMANCE
You can use t/benchmark.pl to test the perfomance. Here is the result on my P4 box. Benchmark: timing 1000000 iterations of perl quote, xs quote... perl quote: 108 wallclock secs (88.08 usr + 0.01 sys = 88.09 CPU) @ 11351.64/s (n=1000000) xs quote: 20 wallclock secs (16.78 usr + 0.00 sys = 16.78 CPU) @ 59591.20/s (n=1000000) Benchmark: timing 1000000 iterations of perl dequote, xs dequote... perl dequote: 106 wallclock secs (85.22 usr + 0.09 sys = 85.31 CPU) @ 11721.54/s (n=1000000) xs dequote: 19 wallclock secs (15.92 usr + 0.02 sys = 15.94 CPU) @ 62743.13/s (n=1000000) AUTHOR
Sergey Skvortsov <skv@protey.ru> SEE ALSO
http://www.w3.org/TR/REC-xml <http://www.w3.org/TR/REC-xml>, perlre COPYRIGHT
Copyright 2003 Sergey Skvortsov <skv@protey.ru>. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2008-06-26 Quote(3pm)
All times are GMT -4. The time now is 12:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy