Results 1 to 3 of 3

Thread: Equivalent UNIX 'cut' command in Windows Powershell

  1. #1
    Join Date
    Jan 2012
    Posts
    96

    Equivalent UNIX 'cut' command in Windows Powershell

    If you are using the UNIX like system, you might have seen that, there we use cut command to extract few fields from a file. For example
    Code:
    cut -d";" -f 4-5 file.txt
    But I need an equivalent cut command in Windows powershell. I used the split command but I didn’t get the same result. Can anyone suggest me a good command?

  2. #2
    Join Date
    Nov 2010
    Posts
    86

    Re: Equivalent UNIX 'cut' command in Windows Powershell

    I tried the following command but it is little more tricky and lengthy.

    Code:
      Get-Content Test.txt | %{"$($_.Split(',')[2..4])"}  | Foreach-Object {$_ -replace " ", ","}

  3. #3
    Join Date
    Aug 2011
    Posts
    564

    Re: Equivalent UNIX 'cut' command in Windows Powershell

    How about the following commands for Windows Shell
    Code:
    PS> get-content test.csv
    name,value1,value2
    foo,1,2
    foo,1,2
    foo,1,2
    foo,1,2
    Code:
    PS> import-csv test.csv | select value1
    
    value1
    ------
    1
    1
    1
    1
    Code:
    PS> import-csv test.csv | foreach-object {[int]$_.value1 + 1}
    2
    2
    2
    2

Similar Threads

  1. Access from command line using the PowerShell
    By Ander K in forum Software Development
    Replies: 4
    Last Post: 29-12-2010, 06:41 AM
  2. Linux and UNIX shutdown command help
    By Morea in forum Operating Systems
    Replies: 4
    Last Post: 27-03-2010, 09:32 PM
  3. Powershell 'Get-Mailbox' command
    By Bracken in forum Software Development
    Replies: 3
    Last Post: 03-06-2009, 07:04 PM
  4. The Linux equivalent of Sun command 'prtdiag'
    By dan-dan in forum Operating Systems
    Replies: 3
    Last Post: 27-05-2009, 02:03 PM
  5. Unix command rm -rf
    By RIMON in forum Software Development
    Replies: 1
    Last Post: 18-03-2009, 09:46 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,823,804.32396 seconds with 16 queries