Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 25-02-2012
Member
 
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?
Reply With Quote
  #2  
Old 25-02-2012
Member
 
Join Date: Nov 2010
Posts: 83
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 " ", ","}
Reply With Quote
  #3  
Old 27-02-2012
Member
 
Join Date: Aug 2011
Posts: 561
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Equivalent UNIX 'cut' command in Windows Powershell"
Thread Thread Starter Forum Replies Last Post
Access from command line using the PowerShell Ander K Software Development 4 29-12-2010 06:41 AM
Linux and UNIX shutdown command help Morea Operating Systems 4 27-03-2010 09:32 PM
Powershell 'Get-Mailbox' command Bracken Software Development 3 03-06-2009 07:04 PM
The Linux equivalent of Sun command 'prtdiag' dan-dan Operating Systems 3 27-05-2009 02:03 PM
Unix command rm -rf RIMON Software Development 1 18-03-2009 09:46 AM


All times are GMT +5.5. The time now is 12:23 PM.