cut columns from file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RMSoares
Posts: 32
Joined: 06 Aug 2012 12:01

cut columns from file

#1 Post by RMSoares » 06 Aug 2012 12:13

Hi,
have 2 files (File_A and File_B ) each have a specifc format (fixed with columns, but with a different size)

ex:
File_A
1120120806SUPPORT 111111
2120120806FORUM 423453

File_B
12HELLO 20120806
22THIS IS A TEST20120806

And i whant that my output must be:
20120806SUPPORT 111111
HELLO 20120806
20120806FORUM 423453
THIS IS A TEST20120806


I need to join this two files, sort by the first 2 characters ans remove it.

To join the files i'm doing
cat File_A File_B > File_C

and to order it
sort File_C > File_D

How can i remove the first two columns ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: cut columns from file

#2 Post by foxidrive » 06 Aug 2012 12:29

Try this: file1.txt and file2.txt are input files, it writes to file3.txt

Code: Select all

@echo off
setlocal DisableDelayedExpansion
< file2.txt (
   for /F "delims=" %%a in (file1.txt) do (
      set file2Line=
      set /P file2Line=
      set "file1Line=%%a"
      setlocal EnableDelayedExpansion   
     >>file3.txt echo(!file1Line:~2!
     >>file3.txt echo(!file2Line:~2!
      endlocal
   )
)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: cut columns from file

#3 Post by foxidrive » 06 Aug 2012 12:39

I misread your post, try this:

Edit: fixed syntax error

Code: Select all

@echo off
setlocal EnableDelayedExpansion
copy /a file1.txt + file2.txt file3.txt
sort file3.txt >file4.txt
   for /F "delims=" %%a in (file4.txt) do (
      set "Line=%%a"
     >>file5.txt echo(!Line:~2!
)

RMSoares
Posts: 32
Joined: 06 Aug 2012 12:01

Re: cut columns from file

#4 Post by RMSoares » 17 Aug 2012 11:29

Great, it works!!!

Tks

Post Reply