locked
Subtract column value by 1 in a tab file RRS feed

  • Question

  • Hi All,

    I have a tab delimited file and I want to subtract 3 tab value by 1 using powershell script

    Please suggest.


    Wednesday, June 17, 2020 6:07 AM

All replies

  • Your input file is not tab delimited and neither is your output file.


    \_(ツ)_/

    Wednesday, June 17, 2020 6:16 AM
  • Please post your script and any error messages.


    \_(ツ)_/

    Wednesday, June 17, 2020 6:33 AM
  • (get-content C:\OriginalFile.txt) -replace '\s+',';' | ConvertFrom-Csv -Delimiter ';' | select col1, col2, @{n="col3"; e={[int]$_.col3 -1}}, col4 | ft * -AutoSize | Out-String | out-file c:\OutputFile.txt



    The opinion expressed by me is not an official position of Microsoft


    • Edited by Vector BCO Wednesday, June 17, 2020 7:38 AM
    • Proposed as answer by Vector BCO Monday, June 22, 2020 1:50 PM
    Wednesday, June 17, 2020 6:53 AM
  • Thanks for the help.

    My file is in below format. I want to change th second occurence of 1,2,3 to 0,1,2 like output file. 

    InputFile:

    9.0
    3
    1 SQLCHAR 0 5 "," 1 Col1 SQL_Latin1_General_CP1_CI_AS
    2 SQLCHAR 0 10 "," 2 Col2 SQL_Latin1_General_CP1_CI_AS
    3 SQLCHAR 0 20 "," 3 Col3 SQL_Latin1_General_CP1_CI_AS

    OutputFile:

    9.0
    3
    1 SQLCHAR 0 5  "," 0 Col1 SQL_Latin1_General_CP1_CI_AS
    2 SQLCHAR 0 10  "," 1 Col2 SQL_Latin1_General_CP1_CI_AS
    3 SQLCHAR 0 20  "," 2 Col3 SQL_Latin1_General_CP1_CI_AS


    Raj

    Wednesday, June 17, 2020 3:43 PM
  • That is absolutely nothing like what you asked originally.  I recommend that you contact a consultant with text processing experience to help you define what you are trying to do.  It is not possible to answer such vague question.

    What You are asking is, "I have arbitrary text and I need to make arbitrary replacements"

    In computer technology we need specific patterns and relations and not vague requests.

    What you will need to do is try to under5stand what programming is and why text processing is a challenge.  If you change one item the approach will likely fail.  Also you need to have a fully predictive structure for the text that never changes in order to devise a processing method.

    Yes I could write a script that would appear to do what you ask but that is not the purpose of this forum.

    No I will not write a general solution to a vague request that completely changes structure when asked twice.


    \_(ツ)_/

    • Proposed as answer by Vector BCO Monday, June 22, 2020 1:50 PM
    Wednesday, June 17, 2020 3:51 PM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Yang Yang

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, July 3, 2020 5:40 AM