Search and replace all spaces between quotes with uderscore

Hello,
I'm new on Powershell and I'm trying to make the script that:
searches over file and replaces all the spaces which have been found between quotes;
removes all quotes (except these which has not value eg "").
For example:
Source file:
string3=string4 string="string1 string2 string23" string8="" string5="string7 string8"
Destination file:
string3=string4 string=string1_string2_string23 string8="" string5=string7_string8
I have been created script that searches the data correctly
$file="c:\scripts\mk.txt"
$data=Get-Content $file
$1
$regex = [regex]@'
(?x) # ignore pattern whitespace option
(?<test>(["'])(?:(?=(\\?))\2.)*?\1)
$data |% {
if ($_ -match $regex){
new-object psobject -property @{
test = $matches['test']
}#when adding "|select-object test" I'm getting the correct data
I have stopped here on search / replace operation (from space to underscore, and by removing the quotes leaving the empty quotes non touched). Can you help me to finish the script?
Thanks!

Try this.  It uses the [Regex] Replace static method, with a script block delegate:
$file="c:\scripts\mk.txt"
$data=Get-Content $file
$regex = '(\S+=[^"\s]+)|(\S+="[^"]+")'
$delegate = { $args[0].value.replace(' ','_') -replace '"(.+)"','$1' }
$data |% { [regex]::Replace($_,$regex,$delegate) }
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

Similar Messages

  • ICloud saved my daughter's Pages documents and replaced all of my documents with hers. My documents are not on iCloud, how do I get them back?

    My daughter saved her Pages documents to my iCloud account on her iPhone while my documents were apparently saved only to my phone. Never had a problem with that until tonight when iCloud synched so now I have all of my daughter's homework but all of my paperwork is gone! I logged into iCloud and it is only her documents there. How do I get my Pages documents back without a backup?
    iphone 4s, version 6.1.3

    If you took the picture on your iPhone, they are still there on your iPhone, unless you specifically deleted a particular picture from your iPhone. And likewise, if the picture was taken on your iPad, it is still there on your iPad, unless you specifically deleted that picture from the iPad.
    Now ... if you're counting on pictures still "being there" from being on the Photostream ... don't count on that, because that's only a temporary place and it has a time limit and a count limit for how many picture it will have. While the pictures you took on your iPhone and iPad will remain on each one respectively (so you won't lose those), it won't necessarily remain on the Photostream part ... which is only for sharing anyway ... and not meant for storage.
    Whatever pictures you had on your Camera Roll and thus is in the backup in iCloud, will still be there.

  • Replacing soft returns with hard returns in search and replace PM7

    How do I search and replace soft returns in PM7 with a
    hard return? What do I type in the find box?

    Yes BigJohnD,
    That is the answer! Thanks so much.
    I had hunted for that chart but had not found it yet.
    Thanks again, You have been so helpful.
    MargoHollis

  • Can I do search and replace in a batch?

    Hi, Everyone:
    Years ago before I start useing Indesign, I had a Chinese Desktop Prepress program named Westwinner, With tahat I could create a file putting all entries  needed to search and replace in, and search and replace all of them in one shot. Now I wonder if I can do the same with Indesign CS4.
    For your reference, the file for batch search I used in Westwinner looks like that:
    x@x'
    y@y'
    z@z'
    etc.
    Thanks for everyone that reply!

    I meant that scripts can be edited in a plain text editor like Notepad on Windows or the equivalnet on Mac. You still need to understand the scripting language. That script should be availble in AppleScript, VBScript (which work only on Mac or Windows, repectively) or JavaScript, which is cross-platform.
    You don't actually need to edit the script itself very much, I suspect, if at all. In the Javascript version (I'm looking at that in the ESTK) on line 116 you'll see: var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")
    This line is telling the script to find the file FindChangeList.txt in the FindChangeSupport folder which shoujld be inthe same folder as the the script itself. All of the instructions for want to find and how to change it are in that text file, which is a tab-delimited file with each find/change operation on a single line. The stucture of that file is described in the comments section above the script code, so you should be able to design a new file to do what you need to do, then change that single line defining the variable to find the new text file and save the script. If you replace the existing FindChangeList.txt with your own file you wouldn't even need to edit the variable, but the script as written is so useful I wouldn want to give it up, so I'd make a new text file, edit the variable, and save the script with a new name for your own searches.
    I'm not really a script writer, myself. I read javascript fairly well so I was able to see how this script works, but if you need more help you probably should move over to the scripting forum and talk to the real experts.

  • Search and replace with comma

    Hello All,
    I want some help. Please help me.
    I have comma delimited Data. When I’m converting Sting to Array, If two commas exists in between then its displaying “Zero” (because its array propriety ). Instead of that I want to display “NaN” .
    Please give me any idea to replace comma to NaN. I tried with Search and Replace but it’s not giving as I expected.
    Munna
    Solved!
    Go to Solution.

    Hello GerdW,
    Thanks you so much for your reply.
    I thought, instead of replacing trailing comma by NaN adding comma before string is more better (because to many string manipulations) But, it’s taking more execution time.
    Munna
    Attachments:
    Search and Replace.vi ‏415 KB

  • Search and Replace String throwing the wrong error message with regexp?

    This came up in a LAVA thread, and I'm not sure if there's a bug here or not. When using Search and Replace string, and using a regular expression of [(G[b|i])], LabVIEW throws error -4622, "There is an unmatched parenthesis in a regular expression."  There are obviously no unmatched parenthesis in that expression, so it seems to me that the wrong error is being thrown. I'm just not sure if that's a syntactically valid regexp. The problem seems to be with nesting [ ]'s inside ( )'s inside [ ]'s. I've tried a couple of regexp resources on the Web, and one suggests it's valid, while the other seems to think it isn't.
    Message Edited by eaolson on 03-13-2007 10:33 AM
    Attachments:
    ATML_StandardUnit2.vi ‏10 KB
    regexp.png ‏5 KB

    adambrewster wrote:
    I think your regexp is invalid.
    In regexps, brackets are not the same as parentheses.  Parens are for grouping, while brackets are for matching one of a class of characters.  Brackets can not be nested.
    If the regexp is replaced with [G[bi]], there is no error, so it's not a matter of nested brackets. I couldn't find anything on the PCRE man page that forbids nested brackets specifically, but it makes sense.
    Your expression "[(G[bi])]", therefore parses as a character class which matches '(', 'G', '[', 'b', or 'i' followed by an unmatched paren, and an unmatched bracket.
    I don't believe that's the case. Replace the regexp with [(Gbi)], and the error goes away. So it's not a matter of the '(' being literal, and then encountering a ')' without a matching '('.
    daveTW wrote:
    what string exactly you want to replace? I think the round braces are not right in this case, since they mark partial matches which are given back by "match regular expression". But you don't want to extract parts of the string, you want to replace them (or delete, with empty <replace string>). So if you leave the outer [( ... )] then your RegEx means all strings with either "Gb" or "Gi".
    It's not my regular expression. A poster at LAVA was having problems with one of his (a truly frightening one), and this seemed to be the element that was causing the problem. I'm pretty sure that the originator of the regexp meant to use G(b|i), which seems like a complicated way of matching "Gb" or "Gi", if you ask me.

  • Problem with search and replace

    I'm workin on Windows XP, Dreamwearver 8
    When I do a search and replace in a site, the changes will be
    made correctly, however, the auto date stamp that I'm using on my
    pages will duplicate on random pages and overwrite text This
    doesn't occur on all pages, and isn't connected with the actual
    change I'm making. Has anyone experienced this?

    Ok Gary, but...
    in a SQLWorksheet write:
    ababab
    Now Edit -> Replace search for b , replace with \nb
    Result (the last b is not replaced):
    a
    ba
    bab
    At this point, I want to have my string back on one line: Edit -> Replace search for \n , replace with (nothing here)
    Result: The search text "\n" was not found.
    And to make it work I have to tick the Regular Expressions checkbox (in this case substitute escaped characters is ignored).
    While I agree that "it is good to have a choice", I personally find it confusing: none of the few text editors I use (Linux or OSX) behaves this way.
    Regards.
    Alessandro

  • Does the labview 8.5 project have a search and replace option that appies to all vi's in the project?

    In 8.2, the only thing the project has to let you search for a vi is "Find vi's on disk", which is redundant since I can do that in windows explorer.  What I want is a way to search for vi's in my application the way the search and replace function works, except I want it to apply to all vi's in a project instead of just the vi's currently loaded in memory.  Do we have this in 8.5?
    -Devin
    I got 99 problems but 8.6 ain't one.

    I'll give an example of what I was trying to do yesterday in 8.2.  I tried to build a source distribution of a large instrument driver.  Since its an instrument driver there is no single top-level vi that contains all vi's - there are different categories of vi's to do different functions on my instrument.  When I'm doing the source distribution I have to do it in several stages since 8.2 doesn't do source distributions right - but thats not really what this post is about.  Anyway, every time I do the distribution I get an error saying CnvrtArrayIntoBitPattern.vi is password protected (and another engineer wrote it and I don't have the password).  So the build fails.  Now I don't know the password, I'll find it out later, but I at least want to know where in the hierarchy this vi is even being called.  I don't know where it is on disk, I don't know what is calling it, it isn't in the project explicitly, it's a dependency.
    If I had a top-level vi that loaded everything, I could just do a search and replace on that vi and find exactly where it is being called in seconds.  But since I am in a project and have no idea where to start looking, there is no way I can find this vi.  Ideally, in 8.5 there would be a search and replace menu option that searches all vi's in a project to find any calls to this vi.  I want to look for all instances of a vi in my project.  It sounds like you still can't really do that in 8.5.
    What I ended up doing is writing a vi that opens all vi's in a folder hierarchy on disk.  I don't know where this vi is, but all vi's in my project are in the same root folder.  So I run my program to open every single project vi.  Then since I know every single vi is open and loaded simultaneously I used the search and replace function on one of them to find all instances of CnvrtArrayIntoBitPattern.vi.  But that is a painstaking process to create a simple search function.
    I think NI is maybe misunderstanding how people are actually using a project.  Not every vi that is being called is going to be explicitly listed in the project.  (Its this same issue that makes source distributions impossible in 8.2 - you can't target dependencies to a support library so every dependency has to be explicitly listed in the project - which is virtually impossible because they are all in different locations and there are hundreds.)  Most people have lots of general purpose vi's they use in many different projects, and they are buried down in code so we aren't even sure where they are all being used.  The new searches you mention assume you already know where the low-level function is and you are looking for their callers.  But sometimes you don't even know where the low level function is.  What if its an NI directory function?  For example, "resample waveform.vi" is an NI function that changed its defaults in 8.2 which meant we had to find every single place we used it and wire "open-interval?" to a constant instead of depending on the default value.  Its in an NI library somewhere and is never listed as a project vi.  So when I needed to find every place through every project that I used this vi, I couldn't do it through  the project manager because there is no search function.  To be practical I add the project-specific vi's to the project, and maybe a couple support directories, but there will always be lots of vi's as dependencies.  But every now and then I'm still going to want to search for one of these vi's.  So in 8.5 there is there still no way to search for vi's that aren't explicitly listed in the project?
    -Devin
    I got 99 problems but 8.6 ain't one.

  • Search and Replace "Column Break" with "Page Break"?

    Hi,
    I have been using the "column break" where I really should have been using the "page break". The page break just makes more sense in my layout.
    Is there anyway to search and replace the column break with a page break?
    Thanks,
    Rhek

  • Search and replace formulas with AppleScript

    Thanks to this forum I've found out that it is possible to search and replace text by other text or formulas with AppleScript in Numbers 3.2
    Does anybody have a script to search and replace a formula or a part of a formula by another formula or a partial formula.
    For example:
    I would like to be able to find:
    = Table1::$b$3
    and replace this by:
    = Table1::$b$4

    De Signature,
    Would this approach work for you...
    This is a very neat way edit a complex formula in a single cell....
    a) Copy and Paste the formula to a new black page in Pages,
    b) Do your Find and Replace, then
    c) Copy and Paste the formulae back into the cell in Numbers.
    It works like a charm.
    Here is an example of how I used this approach...
    Original cell formulae:
    =AVERAGE(
    SMALL(OFFSET(K3,1,0,20,1),1),SMALL(OFFSET(K3,1,0,20,1),2),
    SMALL(OFFSET(K3,1,0,20,1),3),SMALL(OFFSET(K3,1,0,20,1),4),
    SMALL(OFFSET(K3,1,0,20,1),5),SMALL(OFFSET(K3,1,0,20,1),6),
    SMALL(OFFSET(K3,1,0,20,1),7),SMALL(OFFSET(K3,1,0,20,1),8))
    Final version of formulae:
    =AVERAGE(
    SMALL(OFFSET(K3,N1,0,20,1),1),SMALL(OFFSET(K3,N1,0,20,1),2),
    SMALL(OFFSET(K3,N1,0,20,1),3),SMALL(OFFSET(K3,N1,0,20,1),4),
    SMALL(OFFSET(K3,N1,0,20,1),5),SMALL(OFFSET(K3,N1,0,20,1),6),
    SMALL(OFFSET(K3,N1,0,20,1),7),SMALL(OFFSET(K3,N1,0,20,1),8))
    Find Replace: be cautious with the Find, to ensure it is unique, in my this example ",1,", to avoid changing the" ,1)"
    Enjoy...

  • Search and replace with wildcard?

    I always use search and replace with Homesite but I wonder if
    there is a way of using a wildcard? I often want to replace text at
    the beginning and end of variable text. I mean, if I have this:
    <h3>First text</h3>
    <h3>Second text here</h3>
    What I'd like is, using the * as a wildcard, is to use
    something like this:
    Replace <h3>*</h3> with <h2>*</h2>
    Any ideas? Thanks

    Make a backup first, in case this doesn't work (although it should).
    Use this in the Find field:
    countryText = "([^"]*)";
    And this in the Replace field:
    <countryText>$1</countryText>

  • Using a variable in a Powershell search and replace string

    Hi
    a couple of days ago I posted a question about doing a search and replace with wildcards
    Search and repalce with Widcards
    I got a swift and very helpful answer but now I need to build on it.
    In a text file I wanted to replace all the text between two defined words.  the script I got was this
    $text = 'Some Server this bit of text varies Language stuff'
    $text -replace '(.*Server) .+? (Language.*)','$1 it will always say this $2'
    It works great but now I want to replace "it will always say this" with a variable and I can't figure out the correct grammar to make this happen.
    Can anyone help??
    Thanks
    Alex

    Here's one way:
    $replace = 'it will aways say this'if ( $text -match '(.*Server) .+? (Language.*)' )
    { "{0} $Replace {1}" -f $matches[1,2] }
    else { $text }
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • How do I search and replace for invisibles in Pages 5.5.2?

    Three related problems all involving search and replace for invisibles.
    1. A block of text where all double returns need to become single returns.
    2. A block of text where all returns need to be replaced with a single word space.
    3. A block of text where all double word spaces to be replaced with a single word space.
    Pages 09 could do all three this handily. How can these be done in Pages 5.5.2?
    Appreciated.

    Here are screenshot of my attempts to make reducing double returns to one. First up selection of a double return:
    Copy to the clipboard. Do a Command-F. Here's the resulting dialogue:
    I paste in the contents of the clipboard:
    Note the Search field no longer has an empty slot selected. Something is clearly in there, but no instance of whatever is has been found. Nevertheless, I proceed to set up the Replace field by selecting a single return:
    Copy that to the clipboard and paste into the Replace field:
    Nothing to search for and therefore nothing to replace. Am now wondering what that little scoop to the right of the eyeglass icon might indicate. Clicking on it reveals this:
    Definitely not "a solution that just works."

  • RE: (forte-users) search and replace within aTextData

    Welll, you're both right. The MoveToChar makes it unnecessary (if a little
    sloppy) to MoveNext as long as you've changed the character. thus,
    outStr: TextData = new;
    outStr.SetValue(inStr);
    while (outStr.MoveToChar(' ')) do
    outStr.ReplaceRange('_', outStr.Offset, outStr.Offset+1);
    end while;
    return outStr;
    works fine to change blanks to underscores.
    Regards,
    David
    -----Original Message-----
    From: Campbell, Dave [mailto:DCampbellpurolator.com]
    Sent: Friday, 14 January 2000 0:58
    To: 'Matthew Middleton'
    Cc: kamranaminyahoo.com
    Subject: RE: (forte-users) search and replace within a TextData
    If you do not use the MoveNext method to skip beyond the "found" character,
    a subsequent invocation of MoveToChar will find the same character, located
    at exactly the same offset.
    If there is no match, MoveToChar returns FALSE and the current offset does
    not change.
    ----- Original Message -----
    From: Matthew Middleton <mathew.middletonlawpoint.com.au>
    To:kamranaminyahoo.com
    Unless I'm missing something here...you needn't go through every
    character...use MoveToChar()...as per Help...
    while (TextdataObj.MoveToChar (' ')) do
    end while;
    Regards,
    Dave Campbell
    Consultant,
    Caro Systems Inc.
    Mailto:Dave.CampbellCaroSys.com
    For the archives, go to: http://lists.sageit.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.sageit.com

    Why not this:
    while myText.moveToString(' ') do
    myText.ReplaceRange('-', myText.Offset, myText.Offset+1);
    end while;
    or if you prefer verbosity:
    while myText.moveToString(source=' ') do
    myText.ReplaceRange(source='-', startOffset=myText.Offset,
    endOffset=myText.Offset+1);
    end while;
    -----Original Message-----
    From: FatchJeBAM.com [mailto:FatchJeBAM.com]
    Sent: Wednesday, January 12, 2000 2:51 PM
    To: Troy.Burnsvacationclub.com; kamranaminyahoo.com
    Subject: RE: (forte-users) search and replace within a TextData
    How about this?? May have to play with start/end on ReplaceRange as I
    didn't really test this
    Anybody got a better way??
    -- replace space with underscore
    For x in 1 to myTextdata.LengthToEnd() do
    If myTextData.IsSpace() then
    MyTextdata.ReplaceRange('_'. Startoffset=myTextdata.offset,
    endoffset=myTextdata.offset+1);
    End if;
    MyTextdata.MoveNext;
    End for;
    Jerry Fatcheric
    -----Original Message-----
    From: Burns, Troy [mailto:Troy.Burnsvacationclub.com]
    Sent: Wednesday, January 12, 2000 9:40 AM
    To: kamranaminyahoo.com
    Subject: (forte-users) search and replace within a
    TextData
    Hello all,
    I need to search within a textdata object, replacing all
    occurrances of a
    space
    with another character. Can you give a quick code example
    of how I would do
    this?
    Thanks in advance,
    Troy
    Troy Burns
    Marriott Vacation Club Intl.
    E-mail: troy.burnsvacationclub.com
    Phone: (941) 688-7700 ext. 4408
    For the archives, go to: http://lists.sageit.com/forte-users
    and use
    the login: forte and the password: archive. To unsubscribe,
    send in a new
    email the word: 'Unsubscribe' to:
    forte-users-requestlists.sageit.com
    For the archives, go to: http://lists.sageit.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.sageit.com

  • Search and replacing a url...

    I just ran across an issue last night, my hyperlinks added a space at the end of the url. Does anyone know how to do a search and replace for the hyperlink window? I ended up editing every one of them. It probably wouldn't be so bad but that is a lot of repetition that InDesign should be doing.
    Edit: I should mention that I am using CS3 on Windows XP. I am thinking I hit a bug with the above, the spaces should not have been there.

    The document was imported from word 97. Last night I deleted the text and reimported it as I updated a few of the links. (Yeah I know about linking the document) I also added a few directly in InDesign. All hyperlinks except 2 had a space after them, those 2 were imported. Which makes me believe the problem was not with the importing(placing) but perhaps a bug in InDesign. This document use to export to pdf just fine. One thing I had noticed was the paragraph mark on all but those two were marked as a hyperlink. Even though I did a search and replace on all the paragraph marks to remove the hyperlink, the space remained in the url. So I ended up double clicking on each hyperlink in the hyperlink window and manually removing the space at the end of each url.

Maybe you are looking for

  • Idea tab A1000 taking too much time to charge

    I have A ideaTab A1000 and its taing too much time to charge.In first few days its take about 3 hours to charge fully but nowadays its taking 9-10 hours to fully charge and one more thing i.e. Where can i buy A Charger for the same?

  • After upgrading to iTunes 8.0.2, iTunes won't open at all

    I used to use iTunes 7.0.4 and recently tried updating to 8.0.2. Once I installed the new upgrade, iTunes won't open! I double click, use the Run feature, etc etc without any luck. I also tried to re-install an earlier version of iTunes but for whate

  • DMS: Relocation of storage category/documents to another content server

    Our DMS content server was implemented with a 3-tier environment (dev-test-production).  There are several SAP instances storing documents to a shared storage category in the global DMS server. I found recently that one of the production instances on

  • Taxation Invoice

    Hi, During the bill from plant  If some customer doesnot want Taxation Invoice but Industrial customer want taxation Include in the Invoice,how to do in the system? Please give me the solution. Thanks, Liku.

  • Just checked RMA status

    It's been updated & the problem has been diagnosed/confirmed (Headphone jack not functional) My question is: Before a fixed Micro (or a replacement) is sent back, does Creative usually send an email/make a phone call out? Or does the Micro arri've as