none
Automation for deletion of many invoices RRS feed

  • General discussion

  • HI team,

    I am trying to do an automation where the scenario is like: I am having a text file ABC.txt which contains all numbers :

    ABC.txt:

    12234

    12345

    123455

    Through the powershell scripting, I want to have the output in a text file like :

    Sunny day

    Rainy Day

    Windy day

    This is 12234

    This is 12345

    This is 123455

    So I have perform the below scripting:

    $File1 = @((Get-Content "E:\ABC.txt"))
    For($a = 0;$a -lt $File1.count;$a++){
    -join ("This is ", $File1[$a]) | Out-File -FilePath "E:\XYZ.txt" -Append
    }

    The above script is showing output in XYZ.txt file:-

    This is 12234

    This is 12345

    This is 123455

    Can you please let me how to add the following on top of the above output:

    Sunny day

    Rainy Day

    Windy day

    • Changed type Bill_Stewart Thursday, September 5, 2019 9:52 PM
    • Moved by Bill_Stewart Thursday, September 5, 2019 9:53 PM This is not "do homework for me" forum
    Friday, August 9, 2019 3:04 PM

All replies

  • Hi All,

    I am new to Microsoft Powershell. I am stuck in middle of somewhere. Appreciate if I get a help in this matter. Below is the text.file which contains numbers:

    ABC.text

    234567899

    234567890

    233445678

    I want the output to be (in the same file by powershell scripting):

    This is 234567899

    This is 234567890

    This is 233445678

    Can you please help me in creating this.

    Regards,

    ROY

    • Merged by Bill_Stewart Friday, August 9, 2019 5:13 PM Duplicate
    Thursday, August 8, 2019 12:01 PM
  • # Many Way to do this # You must add `n for adding a carriage return and -append parameter (-join("this is ", "$var", "`n")) | Out-File -FilePath $MyOutputFile -Append # or a better way : no needs of CR, it's by design, and the native cmdlet function is to add :-) Add-Content -Value (-join("this is ", "$MyVar")) -Path $MyOutputFile

    # i.e. :

    $MyOutputFile ="c:\temp\Outputfile.txt"

    foreach ($var in $VarCollection) { Add-Content -Value (-join("this is ", "$MyVar")) -Path $MyOutputFile }


    Oliv

    Thursday, August 8, 2019 2:02 PM
  • # Many Way to do this # You must add `n for adding a carriage return and -append parameter (-join("this is ", "$var", "`n")) | Out-File -FilePath $MyOutputFile -Append # or a better way : no needs of CR, it's by design, and the native cmdlet function is to add :-) Add-Content -Value (-join("this is ", "$MyVar")) -Path $MyOutputFile

    # i.e. :

    $MyOutputFile ="c:\temp\Outputfile.txt"

    foreach ($var in $VarCollection) { Add-Content -Value (-join("this is ", "$MyVar")) -Path $MyOutputFile }


    Oliv

    Look at you code.  It has a few obvious mistakes.  Can you find them?  Where in the world is Waldo?

    \_(ツ)_/

    Thursday, August 8, 2019 2:28 PM
  • Hi Oliv,

    I have ran the above code but it is not showing the expected output in ABC.txt file.

    Can you please provide some other solution for this? I want to display the following output in ABC.txt file only

    This is 234567899

    This is 234567890

    This is 233445678

    Regards,

    ROY


    • Edited by Eshan Roy Thursday, August 8, 2019 3:14 PM edit
    Thursday, August 8, 2019 3:13 PM
  • Hi 

    Do u have any solution for this. Can you please share as this is high priority I have to finish this by EOD.

    Thursday, August 8, 2019 3:14 PM
  • Can you please share as this is high priority I have to finish this by EOD.

    I'm afraid you're going to have to adjust your expectations for this forum. Please read this first:

    This forum is for scripting questions rather than script requests


    -- Bill Stewart [Bill_Stewart]



    Thursday, August 8, 2019 3:25 PM
  • Hi Bill,

    Thanks for sharing the information. I have already tried to do it my way. But I failed, so anyhow if I can get some help on this matter it will be helpful for me. 

    Thursday, August 8, 2019 3:30 PM
  • I refer the honorable gentleman to my first reply posted some minutes ago.

    -- Bill Stewart [Bill_Stewart]

    Thursday, August 8, 2019 3:36 PM
  • Why not just output the first three lines that you want, and then do the loop?

    What is the purpose of this script? Is this homework?


    -- Bill Stewart [Bill_Stewart]

    Friday, August 9, 2019 3:29 PM