1

I'm trying to find a way to automate a process from beginning to end.

The details of the process, which I'm doing manually, are as follows:

I have a tab delimited file (.tab file extension). The files have a variable number of rows. I'm using excel to open the files and multiply some of the columns by -1 to negate their values. After negating the values, I save the file.

I'm looking for a way to automate this process, and though that powershell might be capable of doing so, but my searches haven't yielded much useful information.

1 Answers1

0

The components you need are:

  1. Read the file into an array of strings

    $content = Get-Content 'file.tab'
    
  2. Loop over all strings in $content and split each by the tabulator -- the result is another array. Loop over that new array and multiply each entry by -1. Join the so multiplied array to get back the whole row.After you're finished with all strings, assign the complete result to the original array $content again.

    $content = $content | ForEach{($_.split("`t") | ForEach{-$_}) -join "`t"}
    
  3. Output the result as you want. e.g. by using the Out-File cmdlet,

    $content | Out-File 'new_file.tab'
    

EDIT: I did not read the other question which was marked as the original to this duplicate.

davidhigh
  • 14,652
  • 2
  • 44
  • 75