Sponsored Content
Full Discussion: Problems with grep and XML
Top Forums UNIX for Dummies Questions & Answers Problems with grep and XML Post 302092923 by Corona688 on Friday 13th of October 2006 10:45:35 AM
Old 10-13-2006
If you're saving it as UTF-16, you're saving it as 16-bit Unicode, and my guess was right on the money. You can't grep UTF-16. It uses 16-bit characters instead of the normal 8 bits. Grep is comparing half a character of UTF-16 to one full character of some other set. Naturally it won't work.

Can you save it as UTF-8 instead? It can represent all UNICODE characters, without breaking grep.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

problems with grep on solaris 5.8

Hi all, I have a problem when i grep for a particular field among all fhe files in the directory. if i do an ls -l field * i can find it. however at the moment the number of files in the directory are close to 28000 and it returns an ksh: /usr/bin/grep: arg list too long Assuming i... (2 Replies)
Discussion started by: manualvin
2 Replies

2. Shell Programming and Scripting

Grep xml tags

Hi I want to get the value between to XML tags as follows <EAN>12345</EAN> so i would want to return 12345. i have tried sed and awk but can't do it. can anyone help? (9 Replies)
Discussion started by: handak9
9 Replies

3. Shell Programming and Scripting

Grep XML tags

I want to search the below XML pattern in the XML files, but the XML files would be in a .GZ files, <PRODID>LCTO84876</PRODID> <PARTNUMBER>8872AC1</PARTNUMBER> <WWPRODID>MODEL84876</WWPRODID> <COUNTRY>US</COUNTRY> <LANGUAGE>1</LANGUAGE> What's the command/script to search it ? :confused: (2 Replies)
Discussion started by: saravvij
2 Replies

4. Shell Programming and Scripting

Problems in Usage of grep

Hi all, I have a file resp_cde.ats which has values as:- APPDIR=C:\Program Files\Cogny\cert PUBSDIR=C:\Program Files\Cognoy\cert\documentation TOURDIR=C:\Program Files\Cognoy\cert\tour DATADIR=C:\Program Files\Cognoy\cert\data Now I use the grep command in a shell script:- x=`grep... (2 Replies)
Discussion started by: vikasrout
2 Replies

5. Shell Programming and Scripting

Grep/Parse a .xml file

I have a .xml file similar to the following: <Column> <Name>FIELD1</Name> <Title>CO.</Title> </Column> <Column> <Name>FIELD2</Name> <EditField>TextBox</EditField> <ColumnSpan0>4</ColumnSpan0> <Title>NORMAL</Title> ... (12 Replies)
Discussion started by: jl487
12 Replies

6. UNIX for Dummies Questions & Answers

GREP for a tag in XML File

I have 2 XML Data files with a tag named PARTICIPATION_TYPE and i am trying to grep for that and getting unique values. However one of the xml data file data is not aligned properly like below. File 1: (works fine when i do grep) grep "PARTICIPATION_TYPE" file1.xml | sort -u Data: ....... (3 Replies)
Discussion started by: Ariean
3 Replies

7. UNIX for Dummies Questions & Answers

Grep content in xml file

I have an xml file with header as below. <Provider xmlns="http://www.xyzx.gov/xyz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyzx.gov/xyz xyz.xsd" SCHEMA_VERSION="2.5" PROVIDER="5"> I want to get the schema version here that is 2.5 and put in a... (7 Replies)
Discussion started by: Ariean
7 Replies

8. Shell Programming and Scripting

Grep some values from XML file

Dear community, I have a big XML log file containing several rows splitted by tag: <ActivityLogRecord> and </ActivityLogRecord>. An example below. What I need is read the file and extract some value from each tags and put them into one line (each line for every <ActivityLogRecord> tag). So... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

9. Shell Programming and Scripting

How to grep for a word in xml?

Hi, I have the below tag/s in my xml. <foreign-server name="MOHTASHIM_SERVER"> What will be the easist way to extract MOHTASHIM_SERVER without the double quotes "" from the above tag? Desired Output: (10 Replies)
Discussion started by: mohtashims
10 Replies

10. UNIX for Beginners Questions & Answers

How to fetch the value from a xml using sed, GREP?

I have a simple xml file,need the output with the <value> tag and <result> tag text.xml <test-method status="FAIL" duration="45"> <value> Id=C18 </value> <result> wrong paramter </result> </test-method> <test-method status="FAIL" duration="45"> <value> Id=C19 </value> <result> Data... (5 Replies)
Discussion started by: DevAakash
5 Replies
Encode::Unicode(3pm)					 Perl Programmers Reference Guide				      Encode::Unicode(3pm)

NAME
Encode::Unicode -- Various Unicode Transformation Formats SYNOPSIS
use Encode qw/encode decode/; $ucs2 = encode("UCS-2BE", $utf8); $utf8 = decode("UCS-2BE", $ucs2); ABSTRACT
This module implements all Character Encoding Schemes of Unicode that are officially documented by Unicode Consortium (except, of course, for UTF-8, which is a native format in perl). <http://www.unicode.org/glossary/> says: Character Encoding Scheme A character encoding form plus byte serialization. There are seven character encoding schemes in Unicode: UTF-8, UTF-16, UTF-16BE, UTF-16LE, UTF-32 (UCS-4), UTF-32BE (UCS-4BE) and UTF-32LE (UCS-4LE). Quick Reference Decodes from ord(N) Encodes chr(N) to... octet/char BOM S.P d800-dfff ord > 0xffff x{1abcd} == ---------------+-----------------+------------------------------ UCS-2BE 2 N N is bogus Not Available UCS-2LE 2 N N bogus Not Available UTF-16 2/4 Y Y is S.P S.P BE/LE UTF-16BE 2/4 N Y S.P S.P 0xd82a,0xdfcd UTF-16LE 2 N Y S.P S.P 0x2ad8,0xcddf UTF-32 4 Y - is bogus As is BE/LE UTF-32BE 4 N - bogus As is 0x0001abcd UTF-32LE 4 N - bogus As is 0xcdab0100 UTF-8 1-4 - - bogus >= 4 octets xf0x9aaf8d ---------------+-----------------+------------------------------ Size, Endianness, and BOM You can categorize these CES by 3 criteria: size of each character, endianness, and Byte Order Mark. by size UCS-2 is a fixed-length encoding with each character taking 16 bits. It does not support surrogate pairs. When a surrogate pair is encountered during decode(), its place is filled with x{FFFD} if CHECK is 0, or the routine croaks if CHECK is 1. When a character whose ord value is larger than 0xFFFF is encountered, its place is filled with x{FFFD} if CHECK is 0, or the routine croaks if CHECK is 1. UTF-16 is almost the same as UCS-2 but it supports surrogate pairs. When it encounters a high surrogate (0xD800-0xDBFF), it fetches the following low surrogate (0xDC00-0xDFFF) and "desurrogate"s them to form a character. Bogus surrogates result in death. When x{10000} or above is encountered during encode(), it "ensurrogate"s them and pushes the surrogate pair to the output stream. UTF-32 (UCS-4) is a fixed-length encoding with each character taking 32 bits. Since it is 32-bit, there is no need for surrogate pairs. by endianness The first (and now failed) goal of Unicode was to map all character repertoires into a fixed-length integer so that programmers are happy. Since each character is either a short or long in C, you have to pay attention to the endianness of each platform when you pass data to one another. Anything marked as BE is Big Endian (or network byte order) and LE is Little Endian (aka VAX byte order). For anything not marked either BE or LE, a character called Byte Order Mark (BOM) indicating the endianness is prepended to the string. BOM as integer when fetched in network byte order 16 32 bits/char ------------------------- BE 0xFeFF 0x0000FeFF LE 0xFFeF 0xFFFe0000 ------------------------- This modules handles the BOM as follows. o When BE or LE is explicitly stated as the name of encoding, BOM is simply treated as a normal character (ZERO WIDTH NO-BREAK SPACE). o When BE or LE is omitted during decode(), it checks if BOM is at the beginning of the string; if one is found, the endianness is set to what the BOM says. If no BOM is found, the routine dies. o When BE or LE is omitted during encode(), it returns a BE-encoded string with BOM prepended. So when you want to encode a whole text file, make sure you encode() the whole text at once, not line by line or each line, not file, will have a BOM prepended. o "UCS-2" is an exception. Unlike others, this is an alias of UCS-2BE. UCS-2 is already registered by IANA and others that way. Surrogate Pairs To say the least, surrogate pairs were the biggest mistake of the Unicode Consortium. But according to the late Douglas Adams in The Hitchhiker's Guide to the Galaxy Trilogy, "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move". Their mistake was not of this magnitude so let's forgive them. (I don't dare make any comparison with Unicode Consortium and the Vogons here ;) Or, comparing Encode to Babel Fish is completely appro- priate -- if you can only stick this into your ear :) Surrogate pairs were born when the Unicode Consortium finally admitted that 16 bits were not big enough to hold all the world's character repertoires. But they already made UCS-2 16-bit. What do we do? Back then, the range 0xD800-0xDFFF was not allocated. Let's split that range in half and use the first half to represent the "upper half of a character" and the second half to represent the "lower half of a character". That way, you can represent 1024 * 1024 = 1048576 more characters. Now we can store character ranges up to x{10ffff} even with 16-bit encodings. This pair of half-character is now called a surrogate pair and UTF-16 is the name of the encoding that embraces them. Here is a formula to ensurrogate a Unicode character x{10000} and above; $hi = ($uni - 0x10000) / 0x400 + 0xD800; $lo = ($uni - 0x10000) % 0x400 + 0xDC00; And to desurrogate; $uni = 0x10000 + ($hi - 0xD800) * 0x400 + ($lo - 0xDC00); Note this move has made x{D800}-x{DFFF} into a forbidden zone but perl does not prohibit the use of characters within this range. To perl, every one of x{0000_0000} up to x{ffff_ffff} (*) is a character. (*) or x{ffff_ffff_ffff_ffff} if your perl is compiled with 64-bit integer support! SEE ALSO
Encode, <http://www.unicode.org/glossary/>, <http://www.unicode.org/unicode/faq/utf_bom.html>, RFC 2781 <http://rfc.net/rfc2781.html>, The whole Unicode standard <http://www.unicode.org/unicode/uni2book/u2.html> Ch. 15, pp. 403 of "Programming Perl (3rd Edition)" by Larry Wall, Tom Christiansen, Jon Orwant; O'Reilly & Associates; ISBN 0-596-00027-8 perl v5.8.0 2002-06-01 Encode::Unicode(3pm)
All times are GMT -4. The time now is 01:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy