08-02-2011
How to search two strings in a file and print the contents in between to a file
I have a file called po.txt. Here is the content of the file:
<!DOCTYPE PurchaseOrderMessage (View Source for full doctype...)>
- <PurchaseOrder>
- <Header>
<MessageId>cdb3062b-685b-4cd5-9633-013186750e10</MessageId>
<Timestamp>2011-08-01T13:47:23.536-04:00</Timestamp>
</Header>
- <ResponseMessage>
- <Status>
<StatusCode>201</StatusCode>
<StatusText>XML parsing executed and completed successfully, but failed due to invalid data</StatusText>
</Status>
- <ObjectErrors>
<PurchaseOrderRef ponumber="4501408250" />
- <PurchaseOrderLineRef ponumber="4501408250" linenumber="10">
- <Error type="Error">
<ErrorMessage>The catalog product specified is not available</ErrorMessage>
</Error>
</PurchaseOrderLineRef>
</ObjectErrors>
</ResponseMessage>
</PurchaseOrder>
How can I search the file po.txt and only print the file content from "- <ObjectErrors>" to " </ObjectErrors>" to a new file in unix?
- <ObjectErrors>
<PurchaseOrderRef ponumber="4501408250" />
- <PurchaseOrderLineRef ponumber="4501408250" linenumber="10">
- <Error type="Error">
<ErrorMessage>The catalog product specified is not available</ErrorMessage>
</Error>
</PurchaseOrderLineRef>
</ObjectErrors>
thanks for your help!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hello
have a file1
H87I
Y788O
T347U
J23U
and
file2 J23U U887Y I99U T556U
file3 I99O J99T F557J
file4 N99I T666U R55Y
file5 H87I T347U
file6 H77U R556Y E44T
file7 Y788O K98U H8I
May be using script we can use file1 to search for all the files
and have the output
H87I file5... (3 Replies)
Discussion started by: cdfd123
3 Replies
2. Shell Programming and Scripting
Hi,
I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines).
#################################
huge_file.txt
a
a
ab
b
##################################
small_file.txt
a 1.5
b 2.5
ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies
3. Shell Programming and Scripting
Please I want to replace all the contents beween "Section" and "Ensection" in file1 with all contents in file2. Example:
file1:
Section "Screen"
DefaultDepth 24
SubSection "Display"
Depth 8
ViewPort 0 0
Modes "1024x768" "800x600" "640x480"
EndSubsection
SubSection "Display"
Depth... (9 Replies)
Discussion started by: powelltallen
9 Replies
4. Shell Programming and Scripting
Hi Friends,
This is the only solution to my task. So, any help is highly appreciated.
I have a file
cat input1.bed
chr1 100 200 abc
chr1 120 300 def
chr1 145 226 ghi
chr2 567 600 unix
Now, I have another file by name
input2.bed (This file is a binary file not readable by the... (7 Replies)
Discussion started by: jacobs.smith
7 Replies
5. Shell Programming and Scripting
Hi one of the output of the command is as below
# sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/'
Resource List : <br>
*************************** 1. row ***************************<br>
... (2 Replies)
Discussion started by: vivek d r
2 Replies
6. Shell Programming and Scripting
Hi guys,
I have a text file named file1.txt that is formatted like this:
001 , ID , 20000
002 , Name , Brandon
003 , Phone_Number , 616-234-1999
004 , SSNumber , 234-23-234
005 , Model , Toyota
007 , Engine ,V8
008 , GPS , OFF
and I have file2.txt formatted like this:
... (2 Replies)
Discussion started by: An0mander
2 Replies
7. UNIX for Beginners Questions & Answers
I have a data file, file1.txt, such as the following:
1,2 "TWRTW", "TWRH/"
1,2 "JHGH", "HGJ
1,2 "JWMM", "JWMM"
1,2 "W", "W"
1,2 "LJLH", "LJLH/"
1,3 "W", "W"
1,3 "HJH", "HJJ
I have another file, file2.txt, that contains... (3 Replies)
Discussion started by: jvoot
3 Replies
8. Shell Programming and Scripting
The file f1 contains the text "body" (shell prompt is "$"):
$ cat ~/path/f1
body
How to print contents of f1 when the f1 path is in a variable?
Here is my failed attempt:
$ f1="~/path/f1"
$ echo $f1
~/path/f1
$ cat $f1
cat: '~/path/f1': No such file or directory (2 Replies)
Discussion started by: wolfv
2 Replies
9. UNIX for Beginners Questions & Answers
Trying to use sed to insert the contents of a file into the end of each line in another file
file1
This is a line
Here is another line
This is yet another line
Here is a fourth line
file2
TEXT
desired output
This is a line TEXT
Here is another line TEXT
This is yet another... (6 Replies)
Discussion started by: jimmyf
6 Replies
10. UNIX for Beginners Questions & Answers
Hi All,
I hope somebody would be able to help me.
I would need to search a string coming from a file, example file.txt:
dog
cat
goat
horse
fish
For every string, I would need to know if there are any files inside a directory(recursively) that contains the string regardless of case.... (9 Replies)
Discussion started by: kokoro
9 Replies
LEARN ABOUT HPUX
catclose
catopen(3C) catopen(3C)
NAME
catopen(), catclose() - open and close a message catalog for reading
SYNOPSIS
DESCRIPTION
The function opens a message catalog and returns a catalog descriptor. The specifies the name of the message catalog being opened. A con-
taining a slash specifies a path name for the message catalog. Otherwise, the environment variable is used (see environ(5)). If specifies
more than one path, returns the catalog descriptor for the first path on which it is able to successfully open the specified message cata-
log. If does not exist in the environment, or if a message catalog cannot be opened for any path, uses a system-wide default path. The
default is affected by if the value of is If the value of is zero, the default is affected by the environment variable See environ(5) for
details.
If is invoked from or programs with owner root, the environment variable is not directly used to locate message catalogs. Instead, the
paths which are available both in the configuration file and environment variable are considered to locate message catalogs. See
nlspath(4) for details.
Example: If the environment variable is set to:
and the configuration file has an entry:
only path is considered for locating catalog files. This feature is provided only for backward compatibility for those or root programs
which are depending on the environment variable. All new or root programs should not depend on the environment variable and should only
use absolute path names.
A message catalog descriptor remains valid in a process until the process closes it or until a successful call to one of the functions. A
change in the setting of the category may invalidate existing open catalogs.
A file descriptor is used to implement the message catalog descriptor and the close-on-exec flag is set for the message catalog descriptor
(see fcntl(2)).
If is zero, the environment variable is used to locate the catalog. If is the category is used to locate the message catalog only if a
successful call to has been made prior to the call to The result of setting to any other value is undefined.
The function closes the message catalog a message catalog descriptor returned from an earlier successful call to
RETURN VALUE
Upon success, returns a message catalog descriptor. Otherwise, returns a value of (nl_catd)-1 and sets to indicate the error.
Upon success, returns zero. Otherwise, returns -1 and sets to indicate the error.
ERRORS
fails without opening a message catalog and sets for the last path attempted under any of the following conditions:
A component of the path prefix denies search permission, or
read permission is denied for the named file.
The maximum number of file descriptors allowed are currently open.
The length of the specified path name exceeds
bytes, or the length of a component of the path name exceeds bytes while is in effect.
The system file table is full.
The named catalog does not exist or the path is null.
A component of the path prefix is not a directory.
can be used to provide default messages when called following a failed (see catgets(3C)). returns its parameter if it is passed an invalid
catalog descriptor.
fails if the following is true:
is not a valid open message catalog descriptor.
WARNINGS
When using does not provide a default value for
AUTHOR
and were developed by HP.
FILES
Include file containing native language types.
Message catalog default path for core HP-UX products only.
SEE ALSO
fcntl(2), catgets(3C), setlocale(3C), nlspath(4), environ(5), thread_safety(5).
STANDARDS CONFORMANCE
catopen(3C)