Sponsored Content
Top Forums UNIX for Dummies Questions & Answers [Solved] How remove leading whitespace from xml (sed /awk?) Post 302848127 by gacanepa on Wednesday 28th of August 2013 01:58:58 PM
Old 08-28-2013
Try this:
Code:
gacanepa@debian:~$ cat file.xml
 hola
 chau
 me
 voy
gacanepa@debian:~$ awk '{$1=$1}1' file.xml
hola
chau
me
voy
gacanepa@debian:~$

You may want to redirect the output of the last command to an empty file. Hope it helps.
This User Gave Thanks to gacanepa For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

while read loop preserving leading whitespace

Hi all, I've been trying to get this to work for ages to no avail. I've searched this site and googled but cannot find a satisfactory answer. I've got a while loop, like this while read line do echo "$line" done < file_name Now, my problem is that most of the lines in the file... (3 Replies)
Discussion started by: zazzybob
3 Replies

2. Shell Programming and Scripting

sed : remove whitespace

I'm trying to remove the whitespace at the end of each line of a text file in ksh. Im using sed s/ $//g' file1.txt > file2.txt It's not working. Any clues? (3 Replies)
Discussion started by: b.hamilton
3 Replies

3. Shell Programming and Scripting

sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this I'm using sed to remove only the leading spaces in a file bash-280R# cat foofile some text some text some text some text some text bash-280R# bash-280R# sed 's/^ *//' foofile > foofile.use bash-280R# cat foofile.use some text some text some text... (6 Replies)
Discussion started by: laser
6 Replies

4. Shell Programming and Scripting

Remove sections of a xml file with sed

I've been trying to remove some lines of a xml file that looks like this: <parent> <child>name1</child> <lots_of_other tags></lots_of_other_tags> </parent> <parent> <child>name2</child> <lots_of_other tags></lots_of_other_tags> </parent> <parent> <child>name3</child> ... (5 Replies)
Discussion started by: viniciusandre
5 Replies

5. Shell Programming and Scripting

[solved] remove pattern with sed

Hi, i want to remove a certain pattern when i type pwd. pwd will look like this: ..../....../....../Pat_logs/..../....../...../...... the dotted lines are just random directory names, i want it to remove the "Pat_logs/...../....../....../" part so for example: ... (8 Replies)
Discussion started by: a27wang
8 Replies

6. Shell Programming and Scripting

Remove leading zeroes in 2nd field using sed

Hi Forum. I tried searching the forum but couldn't find a solution for my question. I have the following data and would like to have a sed syntax to remove the leading zeroes from the 2nd field only: Before: 2010-01-01|123|1|1000|2000|500|1500|600|700... (18 Replies)
Discussion started by: pchang
18 Replies

7. Shell Programming and Scripting

Sed: Remove whitespace between two strings

I have a 13 number string, some whitespace, and then /mp3. I need to join them. Everyline that I need this for begins with "cd" (without the quotes). What it looks like now: cd media/Audio/WAVE/9781933976334 /mp3 What I want my output to be: cd media/Audio/WAVE/9781933976334/mp3 The 13... (7 Replies)
Discussion started by: glev2005
7 Replies

8. Shell Programming and Scripting

awk to remove leading zeros for a hex number

Is it possible by using awk to remove leading zeros for a hex number? ex: 0000000011179E0A -> 11179E0A Thank you! (4 Replies)
Discussion started by: carloszhang
4 Replies

9. Shell Programming and Scripting

[Solved] awk to remove lines

Hi, I have a file with contents. file1: <2013 tttaaa abc123 <2013 gggdddd <2013 sssssss <2013 eeeee I need to remove the lines which do not have the word "tttaaa" can some one help ? (7 Replies)
Discussion started by: giri_luck
7 Replies

10. Shell Programming and Scripting

awk sed to repeat every character on same position from the upper line replacing whitespace

Hello is it possible with awk or sed to replace any white space with the previous line characters in the same position? I am asking this because the file I have doesn't always follow a pattern. For example the file I have is the result of a command to obtain windows ACLs: icacls C:\ /t... (5 Replies)
Discussion started by: nakaedu
5 Replies
DetectWS(3pm)						User Contributed Perl Documentation					     DetectWS(3pm)

NAME
XML::Filter::DetectWS - A PerlSAX filter that detects ignorable whitespace SYNOPSIS
use XML::Filter::DetectWS; my $detect = new XML::Filter::DetectWS (Handler => $handler, SkipIgnorableWS => 1); DESCRIPTION
This a PerlSAX filter that detects which character data contains ignorable whitespace and optionally filters it. Note that this is just a first stab at the implementation and it may change completely in the near future. Please provide feedback whether you like it or not, so I know whether I should change it. The XML spec defines ignorable whitespace as the character data found in elements that were defined in an <!ELEMENT> declaration with a model of 'EMPTY' or 'Children' (Children is the rule that does not contain '#PCDATA'.) In addition, XML::Filter::DetectWS allows the user to define other whitespace to be ignorable. The ignorable whitespace is passed to the PerlSAX Handler with the ignorable_whitespace handler, provided that the Handler implements this method. (Otherwise it is passed to the characters handler.) If the SkipIgnorableWS is set, the ignorable whitespace is simply discarded. XML::Filter::DetectWS also takes xml:space attributes into account. See below for details. CDATA sections are passed in the standard PerlSAX way (i.e. with surrounding start_cdata and end_cdata events), unless the Handler does not implement these methods. In that case, the CDATA section is simply passed to the characters method. Constructor Options o SkipIgnorableWS (Default: 0) When set, detected ignorable whitespace is discarded. o Handler The PerlSAX handler (or filter) that will receive the PerlSAX events from this filter. Current Implementation When determining which whitespace is ignorable, it first looks at the xml:space attribute of the parent element node (and its ancestors.) If the attribute value is "preserve", then it is *NOT* ignorable. (If someone took the trouble of adding xml:space="preserve", then that is the final answer...) If xml:space="default", then we look at the <!ELEMENT> definition of the parent element. If the model is 'EMPTY' or follows the 'Children' rule (i.e. does not contain '#PCDATA') then we know that the whitespace is ignorable. Otherwise we need input from the user somehow. The idea is that the API of DetectWS will be extended, so that you can specify/override e.g. which elements should behave as if xml:space="preserve" were set, and/or which elements should behave as if the <!ELEMENT> model was defined a certain way, etc. Please send feedback! The current implementation also detects whitespace after an element-start tag, whitespace before an element-end tag. It also detects whitespace before an element-start and after an element-end tag and before or after comments, processing instruction, cdata sections etc., but this needs to be reimplemented. In either case, the detected whitespace is split off into its own PerlSAX characters event and an extra property 'Loc' is added. It can have 4 possible values: o 1 (WS_START) - whitespace immediately after element-start tag o 2 (WS_END) - whitespace just before element-end tag o 3 (WS_ONLY) - both WS_START and WS_END, i.e. it's the only text found between the start and end tag and it's all whitespace o 0 (WS_INTER) - none of the above, probably before an element-start tag, after an element-end tag, or before or after a comment, PI, cdata section etc. Note that WS_INTER may not be that useful, so this may change. xml:space attribute The XML spec states that: A special attribute named xml:space may be attached to an element to signal an intention that in that element, white space should be preserved by applications. In valid documents, this attribute, like any other, must be declared if it is used. When declared, it must be given as an enumerated type whose only possible values are "default" and "preserve". For example: <!ATTLIST poem xml:space (default|preserve) 'preserve'> The value "default" signals that applications' default white-space processing modes are acceptable for this element; the value "preserve" indicates the intent that applications preserve all the white space. This declared intent is considered to apply to all elements within the content of the element where it is specified, unless overriden with another instance of the xml:space attribute. The root element of any document is considered to have signaled no intentions as regards application space handling, unless it provides a value for this attribute or the attribute is declared with a default value. [... end of excerpt ...] CAVEATS
This code is highly experimental! It has not been tested well and the API may change. The code that detects of blocks of whitespace at potential indent positions may need some work. AUTHOR
Enno Derksen is the Original Author. Send bug reports, hints, tips, suggestions to T.J. Mather at <tjmather@tjmather.com>. perl v5.10.0 2001-09-03 DetectWS(3pm)
All times are GMT -4. The time now is 09:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy