I have data in the first and last columns of a tab delimited text file. I want the first and last columns of the file to be deleted using batch. I have tried it using cut
command, but it is not supported by Windows.
-
1Here is an answer for a very similar question. Or you can find a Windows port of cut there.– Paolo GibelliniNov 19, 2013 at 8:16
Add a comment
|
1 Answer
- Input data is in 4 columns separated by tabs (column 3 has embedded spaces).
- If data values do not have spaces then
delims=<tab>
is optional. - Source filename does not have spaces (but output filename may if enclosed: "File 2 Col Out.txt")
Run Command Prompt and enter (substituting actual tab keystroke instead of <tab>
in two places):
CMD /f:off
FOR /f "tokens=2,3 delims=<tab>" %B in (TabFile.txt) do @echo %B<tab>%C>> 2ColFile.txt
CMD /f:on
Example:
c:\DeleteMe>type tabfile.txt
123 ABC Ap ple 321
135 BDF Bro wn 642
c:\DeleteMe>CMD /f:off
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
c:\DeleteMe>FOR /f "tokens=2,3 delims= " %B in (TabFile.txt) do @echo %B %C>> 2ColFile.txt
c:\DeleteMe>type 2colfile.txt
ABC Ap ple
BDF Bro wn
c:\DeleteMe>CMD /f:on