-
October 20th, 2004, 08:55 PM
#1
batch file help
Little help! I'm having some serious brain farts today. I drank a little too much last night. 
Say I have a .txt file that contains some data.
The data is separated by different headings. Something like this:
(data1)
abunchofstuffabunchofstuffabunchofstuffabunchofstuffabunchofstuff
(data1)
(data2)
abunchofstuffabunchofstuffabunchofstuffabunchofstuffabunchofstuff
(data2)
(data3)
abunchofstuffabunchofstuffabunchofstuffabunchofstuffabunchofstuff
(data3)
I want to (from command line or batch file) do a find and output data2 to another file.
So, I'm using
find "(data2)" datafile.txt >> newdatafile.txt
All it copies over is the "(data2)" headings but nothing between.
How can I make it copy ALL the contents between the (data2) headers?
Thanks in advance!
Quitmzilla is a firefox extension that gives you stats on how long you have quit smoking, how much money you\'ve saved, how much you haven\'t smoked and recent milestones. Very helpful for people who quit smoking and used to smoke at their computers... Helps out with the urges.
-
October 20th, 2004, 11:38 PM
#2
What about the following:
Code:
@echo off
rm printflag.
for /F "tokens=1* delims=" %%i in (datafile.txt) do (
if "%%i" == "(data2)" (
if exist printflag. (
del printflag.
) else (
echo printit > printflag.
)
)
if exist printflag. (
echo %%i >> newdatafile.txt
)
)
echo (data2) >> newdatafile.txt
If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)
-
October 21st, 2004, 12:03 AM
#3
good idea. I was thinking that it'd be much easier... but what you say can work too.
Thanks! I'd green but I have to spread.
Quitmzilla is a firefox extension that gives you stats on how long you have quit smoking, how much money you\'ve saved, how much you haven\'t smoked and recent milestones. Very helpful for people who quit smoking and used to smoke at their computers... Helps out with the urges.
-
October 21st, 2004, 05:59 AM
#4
Hi.
It's not a fast solution, but at least it works.
From time to time I am unhappy with the batch-capabilities of the "standard"
windows command shell - unhappy, when I compare with *nix-systems.
From time to time, I have to do stuff like the above on both systems.
Thanks! I'd green but I have to spread
The same occurs to me also regularily ,
when I want to green.
/edit: Hm. I was looking at some of my shell-scripts and adopted one to do the
same as above. Please don't laugh, but can you something more elegant?
A standard-command I missed?
Code:
#!/bin/sh
#assume one instance of the delimiter-pair only
last=`grep -n "(data2)" datafile.txt | awk -F: '{print $1}' |tail -1`
revfirst=`grep -n "(data2)" datafile.txt | awk -F: '{print $1}' |head -1`
revfirst=$(($last-$revfirst+1))
cat datafile.txt |head -$last |tail -$revfirst >>newdatafile.txt
If the only tool you have is a hammer, you tend to see every problem as a nail.
(Abraham Maslow, Psychologist, 1908-70)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|