tag:blogger.com,1999:blog-1306895080225631582.post6416279073953610634..comments2023-05-18T19:57:52.720+05:30Comments on New Delhi PowerShell User Group.: Part-4: Text Manipulation in PowerShell using .Replace(), and .Remove() methods.Amanhttp://www.blogger.com/profile/18237285527131443966noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-1306895080225631582.post-749621834735912692017-07-28T15:52:26.333+05:302017-07-28T15:52:26.333+05:30Hi Guys
Nice article it helpful;Hi Guys<br /><br />Nice article it helpful;Anonymoushttps://www.blogger.com/profile/12365547619415850013noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-32445576009614139562017-01-12T13:03:53.513+05:302017-01-12T13:03:53.513+05:30$text.substring(2) will remove the first 2 charact...$text.substring(2) will remove the first 2 charactersMikel Vhttps://www.blogger.com/profile/13085425526486670817noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-48716020877220248132016-12-01T17:59:57.286+05:302016-12-01T17:59:57.286+05:30It is not working. Please tell how to remove some ...It is not working. Please tell how to remove some starting charactersAnonymoushttps://www.blogger.com/profile/17738515852875915622noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-54445208690804191112016-02-05T09:19:43.525+05:302016-02-05T09:19:43.525+05:30Hello
How can I get the first 7 letters of a stri...Hello<br /><br />How can I get the first 7 letters of a string? The strings can vary in size from 2 to 15 characters long.Anonymoushttps://www.blogger.com/profile/01668672741354641818noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-45618146393330352822015-02-06T12:20:22.628+05:302015-02-06T12:20:22.628+05:30hi Aman can u help me with the syntax to replace d...hi Aman can u help me with the syntax to replace double quote with /"Anonymoushttps://www.blogger.com/profile/12473187257267660413noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-84252418344849157852014-10-02T19:09:39.053+05:302014-10-02T19:09:39.053+05:30Hi Aman, I would like to do following.
20141001-2...Hi Aman, I would like to do following.<br /><br />20141001-2568-C2568-TRX (L)-169082523u.xml rename this file to ABN-2568-C2568-TRX.xml<br />I've 7 files under one folder with similar naming convention.<br /><br />let me know best way to do this.<br /><br />Thank you.hussainmdhttps://www.blogger.com/profile/00147274119727520589noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-44324803165074792592014-08-30T04:54:56.916+05:302014-08-30T04:54:56.916+05:30[string[]]$pdfFileNames = @"
20120911_0712978...[string[]]$pdfFileNames = @"<br />20120911_0712978450876_a.blabla@abcd.com.pdf<br />20120911_1908985424739_a.surname@abcd.com.pdf<br />20120911_0111973455023_brasno45@yahoo.com.pdf<br />20120911_2912971455987_m.forfor@abcd.com.mk.pdf<br />20120911_3110981484777_r.byebye@gmail.com.pdf<br />20120921_0212984415877_a_igor@hotmail.com.pdf<br />20120921_2704975455205_i.lalala@abcd.com.pdf<br />"@ -split "`n"<br /><br />$pdfObject = foreach ($pdfFileName in $pdfFileNames)<br />{<br /> $fileParts = $pdfFileName.Split("_",3)<br /> New-Object -Type PSObject -Property @{<br /> Date = $fileParts[0]<br /> Number = $fileParts[1]<br /> Email = $fileParts[2]<br /> }<br />}<br /><br />$pdfObject |<br /> Select-Object -Property @{Name = "Date_Email";<br /> Expression = {$_.Date + "_" + $_.Email}},Number |<br /> Export-Csv -Path C:\Users\Owner\Tmp\File1.csv<br /><br />$pdfObject |<br /> Select-Object -Property @{Name = "Date_Email";<br /> Expression = {$_.Date + "_" + $_.Email}},Email |<br /> Export-Csv -Path C:\Users\Owner\Tmp\File2.csv<br />Anonymoushttps://www.blogger.com/profile/09513565676772514501noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-47062794592274451482014-04-30T03:22:13.139+05:302014-04-30T03:22:13.139+05:30Thanks, great post. Helped me out :)Thanks, great post. Helped me out :)Anonymoushttps://www.blogger.com/profile/18171782116199113785noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-69159369710525786162014-03-10T08:17:34.599+05:302014-03-10T08:17:34.599+05:30Hi Aman
I have a column with firstnames and lastna...Hi Aman<br />I have a column with firstnames and lastnames from a csv file<br />the firstname column has multiple firstnames.<br />How would i construct the Remove function so that it removes all other words after the first space. <br />E.g. my firsname is Amy May Zan. and the last name is Hakim.<br />How do i just make it Amy.Hakim@email.com?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-65447968816015446832014-01-25T05:39:22.217+05:302014-01-25T05:39:22.217+05:30Hi,
I need to add a word in a text file. I have b...Hi,<br /><br />I need to add a word in a text file. I have bunch of lines in that text file and somewhere in the middle, i have a line like this and i need one more server name at end of the line.<br /><br />$new - "Server10"<br /><br />$Watchers = @( "Server1","Server2","Server3")<br /><br />Please suggest me the script.Unknownhttps://www.blogger.com/profile/14738584299279247634noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-82683135236674573222013-08-31T11:51:57.457+05:302013-08-31T11:51:57.457+05:30Hi Aman i stuck with a problem let's say i hav...Hi Aman i stuck with a problem let's say i have a file with almost 50 lines in it every lines have colon inside a phrase i need to delete or remove all the lines after the colon, ie<br />abcd : aajjnnnaa<br />ab: qwsxx<br />mmmjkkkoo : lopppkk has to be<br /><br />abcd<br />ab<br />mmjkkkoohazzhttps://www.blogger.com/profile/08109037995335449760noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-8683881303395851732013-07-08T16:24:17.970+05:302013-07-08T16:24:17.970+05:30Hi Russ,
Thanks . can you try this .
$csv = Imp...Hi Russ,<br /><br />Thanks . can you try this .<br /><br /><br />$csv = Import-Csv D:\D.csv -Delimiter ","<br /><br /><br /><br />foreach ( $name in $csv ) {<br /><br /><br /> $myName = $name.ccoursenam + $name.teachname<br /><br /> $myName<br /><br /><br /><br />}Amanhttps://www.blogger.com/profile/18237285527131443966noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-48193827970838838472013-06-28T00:17:26.396+05:302013-06-28T00:17:26.396+05:30Hi Aman,
Great work and it answered some questions...Hi Aman,<br />Great work and it answered some questions that I had. I am trying to create a script that will do the following. Reads data from a CSV specifically the teachnam column. The field consists of the users full last name, and the first initial of there first name. It will split this data and combine them to be first initial and last name combined. The longest this field should be is 6 characters. It can be shorter but it cannot be longer. is an example of the csv.<br /><br />teachname,ccoursenam,csection,crefno<br />Smith, J,Algebra II,3,J210<br />Johnson, A,Earth Science,2,S103<br /><br />I am looking for the script to return <br />Smith, J as JSmith<br />Johnson, A as AJohns<br /><br />Here is what I have for code, and I am recieving errors about jsmith not being the correct length.<br /><br />ForEach ($entry In $CSV)<br />{<br />#This line reads the teachname field from the CSV and removes the #space<br />$teachname = $entry.teachname -replace '\s+', ""<br /><br />#This line splits the name up<br />$TeachSplit = $TeacherName.split(",")<br /><br />#This line rearranges in correct order<br />$TeachFull = $TeachSplit[1] + $teachSplit[0]<br /><br />#These next 2 lines Read the length and remove everything after the #6th character<br />$TeachFull.length<br />$TeacherID = $TeachFull.Remove(6)<br />}<br />Any help would be great.Anonymoushttps://www.blogger.com/profile/08635299714753367898noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-48504990579435487172012-10-24T13:40:51.214+05:302012-10-24T13:40:51.214+05:30Hi Aman,
Thanks for the reply...
20120911_071297...Hi Aman,<br /><br />Thanks for the reply...<br /><br />20120911_0712978450876_a.blabla@abcd.com.pdf<br />20120911_1908985424739_a.surname@abcd.com.pdf<br />20120911_0111973455023_brasno45@yahoo.com.pdf<br />20120911_2912971455987_m.forfor@abcd.com.mk.pdf<br />20120911_3110981484777_r.byebye@gmail.com.pdf<br />20120921_0212984415877_a_igor@hotmail.com.pdf<br />20120921_2704975455205_i.lalala@abcd.com.pdf<br /><br />I think this is all you need to create the csv files.<br />This is done by command dir /b (I am sure you know :) )<br /><br />BR<br />Alex.https://www.blogger.com/profile/02711433518917509800noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-63102957494507583282012-10-08T23:49:29.842+05:302012-10-08T23:49:29.842+05:30Hi Alex,
I think that can be done {not sure} , ca...Hi Alex,<br /><br />I think that can be done {not sure} , can you give me few sample file names.<br /><br />thanks<br />amanAmanhttps://www.blogger.com/profile/18237285527131443966noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-73192092160067289282012-09-27T18:24:08.439+05:302012-09-27T18:24:08.439+05:30Hi...I have one problem..Maybe you could help me :...Hi...I have one problem..Maybe you could help me :)<br />I have a folder with PDF files in this format...<br />date_number_email.pdf where date=8 digits , number = 13 digits<br />I have to create two CSV files...<br />1. files.csv with sheet files with two columns, A and B where column A will contain date_email.pdf and column B will contain number<br />2. files.csv with sheet files with two columns, A and B where column A will contain date_email.pdf and column B will contain email<br /><br />Thanks in advance<br /><br />Aleksandar<br />.https://www.blogger.com/profile/02711433518917509800noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-12780266911790503782012-02-28T17:29:11.687+05:302012-02-28T17:29:11.687+05:30Hi Jan
To remove the last 2 digits try
$text.Remo...Hi Jan<br />To remove the last 2 digits try <br />$text.Remove(32)Amanhttps://www.blogger.com/profile/18237285527131443966noreply@blogger.comtag:blogger.com,1999:blog-1306895080225631582.post-70673749367766687962012-02-28T17:24:46.985+05:302012-02-28T17:24:46.985+05:30Hello how can i remove the last 2 digits of my str...Hello how can i remove the last 2 digits of my string:<br /><br />[string]$text = "Archive_Testebene1_20120228_124556"<br /><br />$text.Length<br />$text.Remove(4)<br /><br /><br />With remove it only remove the first 4Jan Freiburghaushttps://www.blogger.com/profile/05225054415872042642noreply@blogger.com