03-20-2013
Splitting records in a text file based on delimiter
A text file has 2 fields (Data, Filename) delimited by # as below,
Data,Filename
Row1 -> abc#Test1.xml
Row2 -> xyz#Test2.xml
Row3 -> ghi#Test3.xml
The content in first field has to be written into a file where filename should be considered from second field.
So from the above example
1. Data 'abc' should be written into a file named Test1.xml
2. Data 'xyz' should be written into a file named Test2.xml
3. Data 'ghi' should be written into a file named Test3.xml
Is it possible to acheive this using Shellscript, please help me with the logic.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I just wandering how to split a record which has more than one delimiter,
i have a file which contains pattern as group separtor and ~ as field separtor, Ultimately I need consider even the groups as a field, So i need to make this multi-delimited file into ~ delimited file.
My record... (4 Replies)
Discussion started by: braindrain
4 Replies
2. Shell Programming and Scripting
I need to split a file based on certain context inside the file. Is there a unix command that can do this? I have looked into split and csplit but it does not seem like those would work because I need to split this file based on certain text. The file has multiple records and I need to split this... (1 Reply)
Discussion started by: matrix1067
1 Replies
3. Shell Programming and Scripting
Hi Everybody,
I need some help on formatting the files coming into unix box on the fly.
I get a file some thing like this in a single line.
ISA^M00^M ^M00^M ^M14^M006929681900 ^M01^M095449419 ... (5 Replies)
Discussion started by: ntekupal
5 Replies
4. Shell Programming and Scripting
All,
We receive a file with a large no of records (records can vary) and we have to split it into two files based on another file. e.g.
File1:
UHDR 2008112
"25187","00000022","00",21-APR-1991,"" ,"D",-000000519,+0000000000,"C", ,+000000000,+000000000,000000000,"2","" ... (2 Replies)
Discussion started by: er_ashu
2 Replies
5. Shell Programming and Scripting
Hi,
I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies
6. Shell Programming and Scripting
Hello gurus,
I am new to "awk" and trying to break a large file having 4 million records into several output files each having half million but at the same time I want to keep the similar key records in the same output file, not to exist accross the files.
e.g. my data is like:
Row_Num,... (6 Replies)
Discussion started by: kam66
6 Replies
7. Shell Programming and Scripting
Hi,
I have a No Delimiter variable length text file with following schema -
Column Name Data length
Firstname 5
Lastname 5
age 3
phoneno1 10
phoneno2 10
phoneno3 10
sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies
8. UNIX for Dummies Questions & Answers
Hi Folks,
I am a novice and need to build a script in bash. I have 2 text files data.txt file is big file, column 2 is the we need to search and delete in the output. The filter file contains the rows to be deleted.
Data.txt
state city zone
Alabama Huntsville 4
California SanDiego 3... (3 Replies)
Discussion started by: tech_frk
3 Replies
9. UNIX for Dummies Questions & Answers
i have a snippet from server log delimited by forward slash.
/a/b/c/d/filename
i need to cut until last delimiter. So desired output should look like:
/a/b/c/d
can you please help?
Thanks in advance. (7 Replies)
Discussion started by: alpha_1
7 Replies
10. Shell Programming and Scripting
Hello I have a file of following format
HDR 1234 abc qwerty
abc def ghi jkl
HDR 4567 xyz qwerty
abc def ghi jkl
HDR 890 mno qwerty
abc def ghi jkl
HDR 1234 abc qwerty
abc def ghi jkl
HDR 1234 abc qwerty
abc def ghi jkl
-Need to split this into multiple files based on tag... (8 Replies)
Discussion started by: wincrazy
8 Replies
LEARN ABOUT DEBIAN
data::stag::hashdb
Data::Stag::HashDB(3pm) User Contributed Perl Documentation Data::Stag::HashDB(3pm)
NAME
Data::Stag::HashDB - build indexes over Stag files or objects
SYNOPSIS
# parsing a file into a hash
my $hdb = Data::Stag::HashDB->new;
$hdb->unique_key("ss_details/social_security_no");
$hdb->record_type("person");
my $obj = {};
$hdb->index_hash($obj);
Data::Stag->parse(-file=>$fn, -handler=>$hdb);
my $person = $obj->{'999-9999-9999'};
print $person->xml;
# indexing an existing stag tree into a hash
my $personset = Data::Stag->parse($fn);
my $hdb = Data::Stag::HashDB->new;
$hdb->unique_key("ss_details/social_security_no");
$hdb->record_type("person");
my $obj = {};
$hdb->index_hash($obj);
$personset->sax($hdb);
my $person = $obj->{'999-9999-9999'};
print $person->xml;
DESCRIPTION
Used for building indexes over Stag files or objects
You need to provide a record_type - this is the type of element that will be indexed
You need to provide a unique_key - this is a single value used to index the record_types
For example, if we have data in the stag structure below, and if ss_no is unique (we assume it is) then we can index all the people in the
database using the code above
publicinfo:
persondata:
person:
ss_details:
social_security_no:
name:
address:
There is a subclass of this method callsed Data::Stag::StagDB, which makes the hash persistent
PUBLIC METHODS -
record_type
Usage -
Returns -
Args -
unique_key
Usage -
Returns -
Args -
index_hash
Usage -
Returns -
Args -
perl v5.10.0 2008-12-23 Data::Stag::HashDB(3pm)