[Solved] How remove leading whitespace from xml (sed /awk?) | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

[Solved] How remove leading whitespace from xml (sed /awk?)

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-28-2013
aniquebmx aniquebmx is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 19 February 2014, 8:59 AM EST
Posts: 8
Thanks: 11
Thanked 0 Times in 0 Posts
[Solved] How remove leading whitespace from xml (sed /awk?)

Hi again

I have an xml file and want to remove the leading white space as it causes me issues later in my script

I see sed is possible but cant seem to get it to work

I tried

Code:
sed 's/^ *//' file.xml


output

Code:
<xn:VsDataContainer id="1U104799" modifier="update">
                                <xn:attributes>
                                        <xn:vsDataType>vsDataExternalUtranCell</xn:vsDataType>
                                        <xn:vsDataFormatVersion>EricssonSpecificAttributes.12.26</xn:vsDataFormatVersion>
                                        <es:vsDataExternalUtranCell>
                                                <es:cellCapability>
<es:hsdschSupport>1</es:hsdschSupport>
<es:edchSupport>0</es:edchSupport>
<es:edchTti2Support>0</es:edchTti2Support>
<es:enhancedL2Support>0</es:enhancedL2Support>
<es:fdpchSupport>0</es:fdpchSupport>
<es:multiCarrierSupport>0</es:multiCarrierSupport>
<es:cpcSupport>0</es:cpcSupport>
<es:qam64MimoSupport>0</es:qam64MimoSupport>

I want all aligned to left

thanks again

paul
Sponsored Links
    #2  
Old 08-28-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 24 October 2014, 10:06 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,237
Thanks: 121
Thanked 453 Times in 412 Posts
Try:

Code:
sed 's/^[[:space:]]*//' file.xml

The Following User Says Thank You to zaxxon For This Useful Post:
aniquebmx (08-29-2013)
Sponsored Links
    #3  
Old 08-28-2013
aniquebmx aniquebmx is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 19 February 2014, 8:59 AM EST
Posts: 8
Thanks: 11
Thanked 0 Times in 0 Posts
no its doesnt work in fact doesnt change file at all thanks though

I have a feeling its about tabs
    #4  
Old 08-28-2013
xbin xbin is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 14 September 2014, 9:02 AM EDT
Posts: 105
Thanks: 5
Thanked 20 Times in 20 Posts
You can read all about it here- Regular expression - Wikipedia, the free encyclopedia

Code:
sed 's/^[[:blank:]]*//' file.xml

The Following User Says Thank You to xbin For This Useful Post:
aniquebmx (08-29-2013)
Sponsored Links
    #5  
Old 08-28-2013
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
code tag tagger
 
Join Date: Sep 2007
Last Activity: 24 October 2014, 10:06 AM EDT
Location: St. Gallen, Switzerland
Posts: 6,237
Thanks: 121
Thanked 453 Times in 412 Posts
@aniquebmx:

Why should it change the file? You didn't ask to change the current file, that's why.
The output you get on the shell should have the leading spaces, whatever they are including tabs, being removed. If not, say so.
To "change" the file, either redirect it into another file and mv it or if your sed is capable of the -i switch it can directly change the file.
You can also use a similar line of perl code with the -i switch for example.
The Following User Says Thank You to zaxxon For This Useful Post:
aniquebmx (08-29-2013)
Sponsored Links
    #6  
Old 08-28-2013
aniquebmx aniquebmx is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 19 February 2014, 8:59 AM EST
Posts: 8
Thanks: 11
Thanked 0 Times in 0 Posts
Hello

apologies Im new here and a lot to learn

the output to shell is still not how I want , therefore to a new file not how i want

output to shell


Code:
                               
                                        <es:vsDataExternalUtranCell>
                                                <es:qQualMin>-16</es:qQualMin>
                                                <es:agpsEnabled>0</es:agpsEnabled>
                                                <es:cellCapability>
                                <es:hsdschSupport>1</es:hsdschSupport>
                                <es:edchSupport>0</es:edchSupport>
                                <es:edchTti2Support>0</es:edchTti2Support>
                                <es:enhancedL2Support>0</es:enhancedL2Support>
                                <es:fdpchSupport>0</es:fdpchSupport>
                                <es:multiCarrierSupport>0</es:multiCarrierSupport>
                                <es:cpcSupport>0</es:cpcSupport>
                                <es:qam64MimoSupport>0</es:qam64MimoSupport>
                                                </es:cellCapability>
                                                <es:qRxLevMin>-115</es:qRxLevMin>
                                                <es:maxTxPowerUl>24</es:maxTxPowerUl>
                                                <es:individualOffset>0</es:individualOffset>
                                                <es:parentSystem>SubNetwork=OSSE_IDF1_R,vsDataExternalUtranPlmn=208_01_2</es:parentSystem>
                                                <es:mncLength>2</es:mncLength>
                                                <es:transmissionScheme>0</es:transmissionScheme>
                                        </es:vsDataExternalUtranCell>

I just need all aligned to left, each line

eg


Code:
<es:vsDataExternalUtranCell>
<es:qQualMin>-16</es:qQualMin>
<es:agpsEnabled>0</es:agpsEnabled>
<es:cellCapability>
<es:hsdschSupport>1</es:hsdschSupport>
<es:edchSupport>0</es:edchSupport>
<es:edchTti2Support>0</es:edchTti2Support>
<es:enhancedL2Support>0</es:enhancedL2Support>
<es:fdpchSupport>0</es:fdpchSupport>
<es:multiCarrierSupport>0</es:multiCarrierSupport>
<es:cpcSupport>0</es:cpcSupport>
<es:qam64MimoSupport>0</es:qam64MimoSupport>
</es:cellCapability>
<es:qRxLevMin>-115</es:qRxLevMin>
<es:maxTxPowerUl>24</es:maxTxPowerUl>
<es:individualOffset>0</es:individualOffset>
<es:parentSystem>SubNetwork=OSSE_IDF1_R,vsDataExternalUtranPlmn=208_01_2</es:parentSystem>
<es:mncLength>2</es:mncLength>
<es:transmissionScheme>0</es:transmissionScheme>
</es:vsDataExternalUtranCell>
</xn:attributes>
</xn:VsDataContainer>
</un:ExternalUtranCell>

thx again

I just tried also


Code:
 
sed 's/^[ \t]*//'  file.xml

also didnt work for the file I want

Last edited by aniquebmx; 08-28-2013 at 12:27 PM..
Sponsored Links
    #7  
Old 08-28-2013
gacanepa gacanepa is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 9 October 2014, 9:12 AM EDT
Location: Villa Mercedes, San Luis, Argentina
Posts: 170
Thanks: 21
Thanked 24 Times in 21 Posts
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.
The Following User Says Thank You to gacanepa For This Useful Post:
aniquebmx (08-29-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sed: Remove whitespace between two strings glev2005 Shell Programming and Scripting 7 01-27-2011 12:10 PM
Remove leading zeroes in 2nd field using sed pchang Shell Programming and Scripting 18 10-04-2010 05:13 PM
sed over writes my original file (using sed to remove leading spaces) laser Shell Programming and Scripting 6 12-02-2008 09:48 AM
sed : remove whitespace b.hamilton Shell Programming and Scripting 3 11-06-2007 10:02 AM
while read loop preserving leading whitespace zazzybob Shell Programming and Scripting 3 06-07-2004 05:36 PM



All times are GMT -4. The time now is 12:09 PM.