03-18-2008
nawk 'BEGIN{n=1}
$0 ~ /^ST/ {f=1}
$0 ~ /^SE/ {invoice[n]=sprintf("%s\n%s",invoice[n],$0);f=0;n=n+1}
{
if (f==1)
invoice[n]=sprintf("%s\n%s",invoice[n],$0)
}
END{
for (i in invoice)
print invoice[i] >> i
close(i)
}' filename
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
I have a config file with multiple section and a parameter with the same name in each section. I need to read each parameter for distinct section.
Parameter = 1
....
Parameter = 2
....
Parameter = 4
....
Tried this:
grep -m1 '^*ProcessorsNumber' ServiceBrokerFramework.cfg |... (7 Replies)
Discussion started by: potro
7 Replies
2. UNIX for Advanced & Expert Users
I have a file that I need to parse multiple sections from the file.
The file contains multiple lines that start with ST (Abunch of data)
Then the file contains multiple lines that start with SE (Abunch of data)
SE*30*0001 ... (1 Reply)
Discussion started by: rgentis
1 Replies
3. Shell Programming and Scripting
Hi,
I need to extract data from a text file in which data has a pattern. I need to extract all repeated pattern and then save it to different files.
example:
input is:
ST*867*000352214
BPT*00*1000352214*090311
SE*1*1
ST*867*000352215
BPT*00*1000352214*090311
SE*1*2
... (5 Replies)
Discussion started by: apjneeraj
5 Replies
4. Shell Programming and Scripting
Hello,
I'm wondering where I could go to learn how to edit file sections that cross multiple lines. I'm wanting to write scripts that will add Gnome menu entries for all users on a system for scripts I write, etc. I can search an replace simple examples with sed, but this seems more complex.
... (8 Replies)
Discussion started by: Narnie
8 Replies
5. UNIX for Dummies Questions & Answers
Hi all,
I need to extract lines between the lines 'RD' and 'QA' from a text file (following). there are more that one of such pattern in the file and I need to extract all of them. however, the number of lines between them is varied in the file. Therefore, I can not just use 'grep -A' command.... (6 Replies)
Discussion started by: johnshembb
6 Replies
6. Programming
Hi All,
I have a file with the data 10;20;30;40;50;60;70;80;123;145;156;345. the output i want is the first fourth sixth elements and everything from there on. How do i achieve this. (1 Reply)
Discussion started by: raghu_shekar
1 Replies
7. Shell Programming and Scripting
input file
Desired csv output
gc_type, date/time, milli secs
af, Mar 17 13:09:04 2011, 144.596
af, Mar 20 00:37:37 2011, 144.242
af, ar 20 21:30:59 2011, 108.518
Hi All,
Any help in acheiving the above would be appreciated. I would like to parse through lines within one file and... (5 Replies)
Discussion started by: satish.vampire
5 Replies
8. Shell Programming and Scripting
Hi all,
Please go through my requirement.
I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch
This file contains the follwing pattern data
<af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624">
<minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies
9. Shell Programming and Scripting
I have a file that has some lines starts with *
I want to get these lines, then get the word between "diac" and "lex".
ex.
file:
;;WORD AlAx
*0.942490 diac:Al>ax lex:>ax_1 bw:Al/DET+>ax/NOUN+ gloss:brother pos:noun prc3:0 prc2:0 prc1:0 prc0:Al_det per:na asp:na vox:na mod:na gen:m num:s... (4 Replies)
Discussion started by: Viernes
4 Replies
10. Shell Programming and Scripting
I have a log that looks like below
sc.mng_10_Err.20131020_000000.log:NCSSC_MNG_UP_PE_TO_BE : Failed to change dvc_trx_sts from PE to BE for srvtrx: 213323141427349 dvcsfx: 1
sc.mng_4_Err.20131020_000000.log:NCSSC_MNG_UP_PE_TO_BE : Failed to change dvc_trx_sts from PE to BE for srvtrx:... (6 Replies)
Discussion started by: senormarquez
6 Replies
LEARN ABOUT PHP
yaml_parse
YAML_PARSE(3) 1 YAML_PARSE(3)
yaml_parse - Parse a YAML stream
SYNOPSIS
mixed yaml_parse (string $input, [int $pos], [int &$ndocs], [array $callbacks])
DESCRIPTION
Convert all or part of a YAML document stream to a PHP variable.
PARAMETERS
o $input
- The string to parse as a YAML document stream.
o $pos
- Document to extract from stream ( -1 for all documents, 0 for first document, ...).
o $ndocs
- If $ndocs is provided, then it is filled with the number of documents found in stream.
o $callbacks
- Content handlers for YAML nodes. Associative array of YAML tag => callable mappings. See parse callbacks for more details.
RETURN VALUES
Returns the value encoded in $input in appropriate PHP type or FALSE on failure. If $pos is -1 an array will be returned with one entry
for each document found in the stream.
EXAMPLES
Example #1
yaml_parse(3) example
<?php
$yaml = <<<EOD
---
invoice: 34843
date: "2001-01-23"
bill-to: &id001
given: Chris
family: Dumars
address:
lines: |-
458 Walkman Dr.
Suite #292
city: Royal Oak
state: MI
postal: 48046
ship-to: *id001
product:
- sku: BL394D
quantity: 4
description: Basketball
price: 450
- sku: BL4438H
quantity: 1
description: Super Hoop
price: 2392
tax: 251.420000
total: 4443.520000
comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.
EOD;
$parsed = yaml_parse($yaml);
var_dump($parsed);
?>
The above example will output something similar to:
array(8) {
["invoice"]=>
int(34843)
["date"]=>
string(10) "2001-01-23"
["bill-to"]=>
&array(3) {
["given"]=>
string(5) "Chris"
["family"]=>
string(6) "Dumars"
["address"]=>
array(4) {
["lines"]=>
string(34) "458 Walkman Dr.
Suite #292"
["city"]=>
string(9) "Royal Oak"
["state"]=>
string(2) "MI"
["postal"]=>
int(48046)
}
}
["ship-to"]=>
&array(3) {
["given"]=>
string(5) "Chris"
["family"]=>
string(6) "Dumars"
["address"]=>
array(4) {
["lines"]=>
string(34) "458 Walkman Dr.
Suite #292"
["city"]=>
string(9) "Royal Oak"
["state"]=>
string(2) "MI"
["postal"]=>
int(48046)
}
}
["product"]=>
array(2) {
[0]=>
array(4) {
["sku"]=>
string(6) "BL394D"
["quantity"]=>
int(4)
["description"]=>
string(10) "Basketball"
["price"]=>
int(450)
}
[1]=>
array(4) {
["sku"]=>
string(7) "BL4438H"
["quantity"]=>
int(1)
["description"]=>
string(10) "Super Hoop"
["price"]=>
int(2392)
}
}
["tax"]=>
float(251.42)
["total"]=>
float(4443.52)
["comments"]=>
string(68) "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338."
}
NOTES
Warning
Processing untrusted user input with yaml_parse(3) is dangerous if the use of unserialize(3) is enabled for nodes using the
!php/object tag. This behavior can be disabled by using the yaml.decode_php ini setting.
SEE ALSO
yaml_parse_file(3), yaml_parse_url(3), yaml_emit(3).
PHP Documentation Group YAML_PARSE(3)