Computing.Net > Forums > Programming > Batch: multiple tokens

Batch: multiple tokens

Reply to Message Icon

Original Message
Name: marto
Date: March 15, 2008 at 16:56:46 Pacific
Subject: Batch: multiple tokens
OS: Vista
CPU/Ram: /
Model/Manufacturer: /
Comment:

Hi everyone,

I'd like to extract some words out of a txt file.

Here's an example:
mcdonnalds@pc1 account: marto/pass1
burgerking@pc2 account: test/pass2
Now I want to extract the words "mcdonnalds", "marto" and "pass1" into a new txt all on thesame line. And I'd like to have thesame for everyline again.

I hope you guys can fix this.

Thx in advance ;)



Report Offensive Message For Removal


Response Number 1
Name: ghostdog
Date: March 15, 2008 at 20:52:15 Pacific
Subject: Batch: multiple tokens
Reply: (edit)

if you can download and install gawk here http://gnuwin32.sourceforge.net/pac...

code:

BEGIN {
FS="[@:]" #set field delimiter to @ and :
}
/mcdonnalds/{
print $1,$3 # print 1st(mcdonnalds) and 3rd field (marto/pass1)
# if you don't want the / , uncomment the below line
# sub("/","",$3)
}

save the above as script.awk and from command line

c:\test> gawk -f script.awk myfile.txt > newfile


Report Offensive Follow Up For Removal

Response Number 2
Name: IVO
Date: March 16, 2008 at 03:51:45 Pacific
Subject: Batch: multiple tokens
Reply: (edit)

@echo off> fileOUT.txt
for /f "tokens=1,3,4 delims=@:/" %%a in (fileIN.txt) do (
echo.%%a %%b %%c >> fileOUT.txt)
:: End_Of_Batch


Report Offensive Follow Up For Removal

Response Number 3
Name: marto
Date: March 16, 2008 at 06:27:02 Pacific
Subject: Batch: multiple tokens
Reply: (edit)

Thx for the replies.

I used IVO's bat, because it doesn't need external tools.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch: multiple tokens

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge