Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

remove specific spaces within some patternme

by gdanenb (Acolyte)
on Oct 24, 2011 at 09:52 UTC ( #933335=perlquestion: print w/ replies, xml ) Need Help??
gdanenb has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I'm looking for a way to remove spaces only according specific pattern in a string using perl in command line.

For example:

f none jboss/docs/licenses/Common Public License v1.0 - cpl-v10.html=$ +CELL/docs/licenses/Common Public License v1.0 - cpl-v10.html 0644 $CE +LL_USER $CELL_GROUP to be: f none jboss/docs/licenses/CommonPublicLicensev1.0-cpl-v10.html=$CELL/ +docs/licenses/CommonPublicLicensev1.0-cpl-v10.html 0644 $CELL_USER $C +ELL_GROUP

Comment on remove specific spaces within some patternme
Download Code
Re: remove specific spaces within some patternme
by pvaldes (Chaplain) on Oct 24, 2011 at 10:19 UTC

    Can you explain better how is your expected data and the desired pattern that you want to match?

    perl -pi'*.bak' -e 's/Common Public License v/CommonPublicLicensev/' m +yfile perl -pi'*.bak' -e 's/\s-\s/-/' myfile

    Update. Or even better:

    perl -pi.bak -e 's/Common Public License v/CommonPublicLicensev/' -e 's/\s-\s/-/' myfile

    And second update. It seems that the desired patterns can appear several times in the same line, so you need to add a final g here: 's/Common Public License v/CommonPublicLicensev/g' and here 's/\s-\s/-/g'

    And that's all

      The string I posted was just an example
      It's taken from Solaris Prototype file used for packaging.
      So,it much more than that

      f none jboss/docs/licenses/BSD style license - bsd.txt=$CELL/docs/lice +nses/BSD style license - bsd.txt 0644 $CELL_USER $CELL_GROUP f none jboss/docs/licenses/BSD style - license.html=$CELL/docs/license +s/BSD style - license.html 0644 $CELL_USER $CELL_G ROUP f none jboss/docs/licenses/Common Development And Distribution License + (CDDL) Version 1.0 - cddl.html=$CELL/docs/licenses/Common Developmen +t And Distribution License (CDDL) Version 1.0 - cddl.html 0644 $CELL_ +USER $CELL_GROUP
        It seems that you don't have here a decently constant pattern. Alternativelly you could also replace all spaces by "nothing" and then restore two or three exceptions, like fnonejboss, etc. It depends a lot on your specific input data file
        perl -pe 's: (?!.*\bjboss/)(?=.* 0644 )::g'
Reaped: Re: remove specific spaces within some patternme
by NodeReaper (Curate) on Oct 24, 2011 at 13:53 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://933335]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-11-26 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (166 votes), past polls