Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows command for cutting columns from a text

The following content is stored in a file:

chrome.exe                   512 Console                 0     73,780 K
chrome.exe                   800 Console                 0     11,052 K
chrome.exe                  1488 Console                 0     92,720 K
chrome.exe                  1600 Console                 0     32,344 K
chrome.exe                  2240 Console                 0     35,132 K
chrome.exe                  2360 Console                 0     21,276 K
chrome.exe                  3524 Console                 0     66,732 K
chrome.exe                  3924 Console                 0     23,524 K

Is there a way to extract the 5th column with the Windows command line?

Something like the UNIX cut command.

like image 519
Vineel Kumar Reddy Avatar asked Dec 14 '10 16:12

Vineel Kumar Reddy


3 Answers

Use double % in variable

for /f "tokens=5 delims= " %%i in (file.txt) DO echo %%i
like image 179
Sonny Saluja Avatar answered Oct 16 '22 15:10

Sonny Saluja


If you're familiar with the GNU cut utility, you might be better off using the Win32 port:

http://gnuwin32.sourceforge.net/packages/coreutils.htm

like image 23
bcosca Avatar answered Oct 16 '22 15:10

bcosca


@ECHO OFF

for /F "tokens=2-4" %%a in (%1) DO ( echo %%a %%b %%c )

took me a long time to find out that %%a %%b %%c .... [%%z] refer to subsequent colums in a text file. So this example will extract the 2nd, 3rd and 4th column (word) from a textfile (%1).

like image 45
missing awk Avatar answered Oct 16 '22 15:10

missing awk