How to count records in unix
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 194
- Joined: Thu May 11, 2006 9:42 am
How to count records in unix
Hi ,
In XML i am having records, every record is separated by delilmiter(@@#),so based on this delimiter i want to count the number of records.
so can you help me with syntax how to count records..
In XML i am having records, every record is separated by delilmiter(@@#),so based on this delimiter i want to count the number of records.
so can you help me with syntax how to count records..
Thanks,
Chris Jones
Chris Jones
I don't think I've ever seen XML with delimiters like that, but regardless...
Clarify exactly what you've got. Is it one long 'record' that you need to break apart around this three-character delimiter or something else? If you do a 'wc -l' on the file, does it return a 1?
I don't recall any built in function that can handle a delimiter like that. You may need to build something like an awk script - or a C program - to read the file and handle the records based on those delimiters. How are you parsing this now?
What's your ultimate goal with all of these 'in UNIX' questions? Perhaps if you said what you were attempting to do at a more strategic (not tactical) level you could get some better advice on how to approach it...
Clarify exactly what you've got. Is it one long 'record' that you need to break apart around this three-character delimiter or something else? If you do a 'wc -l' on the file, does it return a 1?
I don't recall any built in function that can handle a delimiter like that. You may need to build something like an awk script - or a C program - to read the file and handle the records based on those delimiters. How are you parsing this now?
What's your ultimate goal with all of these 'in UNIX' questions? Perhaps if you said what you were attempting to do at a more strategic (not tactical) level you could get some better advice on how to approach it...
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 194
- Joined: Thu May 11, 2006 9:42 am
How to count records in unix
Thanks Hullet for your quick reply,
Actually i am generating an xml file by combining DAT Files using unix script ,in that single xml file i am having multple records separated by delimiter(@@#),so i want to count the number of records in that xml file in order to compare the records in the xml file with Flag file records in order to make sure that we receive the correct records from source..
Thanks,
Chris
i aim to
Actually i am generating an xml file by combining DAT Files using unix script ,in that single xml file i am having multple records separated by delimiter(@@#),so i want to count the number of records in that xml file in order to compare the records in the xml file with Flag file records in order to make sure that we receive the correct records from source..
Thanks,
Chris
i aim to
chulett wrote:I don't think I've ever seen XML with delimiters like that, but regardless...
Clarify exactly what you've got. Is it one long 'record' that you need to break apart around this three-character delimiter or something else? If you do a 'wc -l' on the file, does it return a 1?
I don't recall any built in function that can handle a delimiter like that. You may need to build something like an awk script - or a C program - to read the file and handle the records based on those delimiters. How are you parsing this now?
What's your ultimate goal with all of these 'in UNIX' questions? Perhaps if you said what you were attempting to do at a more strategic (not tactical) level you could get some better advice on how to approach it...
Thanks,
Chris Jones
Chris Jones
A piece of advice. These questions are more appropriate for a Unix forum rather than DataStage. I am not saying we wont help you, dont get me wrong, what i am trying to imply here is that you will get answers more quickly or even find them by googling it much faster.
Regards,
Regards,
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
-
- Charter Member
- Posts: 166
- Joined: Wed Mar 16, 2005 6:52 am
- Location: Mumbai, India
with the limited detail available this is what I'd try out:
If the XML File has only one delimiter present per line:
grep -c Displays only a count of matching lines.
for More information check "man grep" in Unix.
Using DataStage:
Read in the entire file (Folder Stage). Use the DCount() function. Search the BASIC guide for more details.
If the XML File has only one delimiter present per line:
grep -c Displays only a count of matching lines.
for More information check "man grep" in Unix.
Using DataStage:
Read in the entire file (Folder Stage). Use the DCount() function. Search the BASIC guide for more details.
Amey Vaidya<i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
I am rarely happier than when spending an entire day programming my computer to perform automatically a task that it would otherwise take me a good ten seconds to do by hand.</i>
<i>- Douglas Adams</i>
grep -c will only return 1 if there are no line terminators. The OP has still not confirmed whether is a single huge line or multiple lines. For that he needs to perform a sed operation to replace the martian delimiter with a LF and then simply do a wc -l. That should do it.
Something like
Something like
Code: Select all
sed 's/@@#/\n/g' yourFile.xml | wc -l
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.