[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Trim whitespace between quotes - unix shell script

Posted on 2010-03-25
5
Medium Priority
?
456 Views
Last Modified: 2013-12-26
i'm working in a shell script that will do some post process tasks to an XML documnet, the XMLwill be outputted with whitespace after some of the values, i need a way of removing the whitespace but only between the double quotes

<ShipNoticeItem lineNumber="50  " quantity="     0">

I've tried a couple of sed commands but i remove the whitespace between the node name and attributes

Ian
0
Comment
Question by:IanPaskin
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
lanboyo earned 1000 total points
ID: 28569448
If the info in the quotes is always a number (or begins and ends with a number) the following will work.

cat gus3
<ShipNoticeItem lineNumber="50  " quantity="     0">
 


$ sed   ' s/\"\ \ *\([0-9]\)/\"\1/g ' gus3 |  sed   ' s/\([0-9]\)\ \ *\"/\1\"/g '



<ShipNoticeItem lineNumber="50" quantity="0">
0
 

Author Closing Comment

by:IanPaskin
ID: 31707116
Perfect thanks, i never thought to use the fact that it will be numeric.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 28601674
That sed statement can be simplified to

sed 's/" *\([0-9]*\) *"/"\1"/g'
0
 
LVL 10

Expert Comment

by:lanboyo
ID: 28692888
This might trim whitespace between the outside of two quotes.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 28719035
lanboyo.

Can you give an example?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question