Findstr on 1 file and outputting variables to an outfile
Hi,
I am quite new to the scripting world. I am wondering if you could help me out here.
I have a file in a directory (InFile) and would need to compare them to a file similar to what Excel's vlookup is for (CompareFile).
Each line in InFile has multiple tokens and they are delimited by ",". I am only interested in comparing token # 1 and # 3 with the CompareFile. Let's assume token #1 = My_date and token #3 = My_customer.
CompareFile has layout of My_date, My_customer and Customer_Address.
I am trying to write a batch file that would read the InFile and then find any lines that have both token #1 and #3 on it, and then output it to OutFile with token #1, #3 and the CustomerAddress. (I wasn't able to extract tokens #1 and #3 using the "tokens=1,3
delim=," so I have modified it to extract a substring from the whole line.
I currently have the following codes but it's not producing the outfile for me and I don't know why. Would you mind pointing me to the right direction please? Thanks.
SET InFile=InFile.csv
FOR /F %%A IN (%InFile%) DO CALL :FindString "%%A"
pause
GOTO :eof
:FindString
SET my_filename=%1
for /f "delims=" %%x in (%my_filename) do
set my_str=%%x
set my_timestamp=%my_str:~0,18%
set my_cmts=%my_str:~25,12%
findstr /irc:%my_timestamp%.*%my_cmts% CompareFile echo > OutFile
pause
pause
GOTO :eof
There are a few problems in your batch file. The code below resolves all except for the last one.
- The word "do" must be followed by a command or by a parenthesis.
- Instead of writing "%filename%" you wrote "%filename".
- You must use "delayed expansion" when changing variables inside a loop.
- I cannot work out what you're trying to do with your "find" command.
@echo off
SetLocal EnableDelayedExpansion
SET InFile=InFile.csv
set outfile=outfile.txt
FOR /F %%A IN (%InFile%) DO CALL :FindString "%%A"
pause
GOTO :eof
:FindString
for /f "delims=" %%x in (%1) do (
set my_str=%%x
set my_timestamp=%my_str:~0,18%
set my_cmts=!my_str:~25,12!
findstr /irc:!my_timestamp!.*!my_cmts! CompareFile echo > %OutFile%
pause
pause
GOTO :eof
Similar Messages
-
In trace file and output file showing bind variable instead of value
Hi,
database 9i
optimizer = choose(for cost based)
In my trace file and output file showing bind variable instead of value.
in my trace file 20 queries.
I alse set this parameter in session level.
alter session set events '10046 trace name context forever, level 4';
but still showing traceoutput file bind variable.
Pls help its very urgentCan you post the query for which the bind variable values are not being shown and the trace output for the same?
Probably it is listed down somewhere when you actually executed the query among the others. Try completely analyzing your trace file.. -
Open module for managing property file and environment variables
Looking for an open module for managing property files and environment variables (like CLASSPATH) set in a shell script. For handeling properties (preserving comments, supporting includes, appending new entries, and more) I have looked at SuperProperties from openadaptor but find certain functionality lacking. As for interfacing with common shell scripts/files containing setting for CLASSPATH, JAVA_HOME, other system/application variables another type of object editor is needed. Maybe JFIG?
Any ideas are greatly welcomed.You seem wright, you hit a brick wall here with Air to find the location
of the command console on windows...
So in fact I never build an exe tool, but this little problem was a nice
case to test it and I tried it.:
I downloaded monodevelop
-GTK# for .NET 2.12.10*
-MonoDevelop 2.4.2*
from http://monodevelop.com/Download
created a console project and had an exe in 5 minutes !
You can download the findconsole tool and the projectfiles here:
http://greencollective.nl/temp/dump/findconsole_monoproject.zip
findconsole.exe will reveal the path/location of cmd.exe on a windows system.
Cheers,
Latcho -
How can I input read a line from a file and output it into the screen?
How can I input read a line from a file and output it into the screen?
If I have a file contains html code and I only want the URL, for example, www24.brinkster.com how can I read that into the buffer and write the output into the screen that using Java?
Any help will be appreciate!
======START FILE default.html ========
<html>
<body>
<br><br>
<center>
<font size=4 face=arial color=#336699>
<b>Welcome to a DerekTran's Website!</b><br>
Underconstructions.... <br>
</font> </center>
<font size=3 face=arial color=black> <br>
Hello,<br>
<br>
I've been using the PWS to run the website on NT workstation 4.0. It was working
fine. <br>
The URL should be as below: <br>
http://127.0.0.1/index.htm or http://localhost/index.htm
<p>And suddently, it stops working, it can't find the connection. I tried to figure
out what's going on, but still <font color="#FF0000">NO CLUES</font>. Does anyone
know what's going on? Please see the link for more.... I believe that I setup
everything correctly and the bugs still flying in the server.... <br>
Thank you for your help.</P>
</font>
<p><font size=3 face=arial color=black>PeerWebServer.doc
<br>
<p><font size=3 face=arial color=black>CannotFindServer.doc
<br>
<p><font size=3 face=arial color=black>HOSTS file is not found
<br>
<p><font size=3 face=arial color=black>LMHOSTS file
<br>
<p><font size=3 face=arial color=black>How to Setup PWS on NT
<BR>
<p><font size=3 face=arial color=black>Issdmin doc</BR>
Please be patient while the document is download....</font>
<font size=3 face=arial color=black><br>If you have any ideas please drop me a
few words at [email protected] </font><br>
<br>
<br>
</p>
<p><!--#include file="Hits.asp"--> </p>
</body>
</html>
========= END OF FILE ===============Hi!
This is a possible solution to your problem.
import java.io.*;
class AddressExtractor {
public static void main(String args[]) throws IOException{
//retrieve the commandline parameters
String fileName = "default.html";
if (args.length != 0) fileName =args[0];
else {
System.out.println("Usage : java AddressExtractor <htmlfile>");
System.exit(0);
BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
StreamTokenizer st = new StreamTokenizer(in);
st.lowerCaseMode(true);
st.wordChars('/','/'); //include '/' chars as part of token
st.wordChars(':',':'); //include ':' chars as part of token
st.quoteChar('\"'); //set the " quote char
int i;
while (st.ttype != StreamTokenizer.TT_EOF) {
i = st.nextToken();
if (st.ttype == StreamTokenizer.TT_WORD) {
if (st.sval.equals("href")) {
i = st.nextToken(); //the next token (assumed) is the '=' sign
i = st.nextToken(); //then after it is the href value.
getURL(st.sval); //retrieve address
in.close();
static void getURL(String s) {
//Check string if it has http:// and truncate if it does
if (s.indexOf("http://") > -1) {
s = s.substring(s.indexOf("http://") + 7, s.length());
//check if not mailto: do not print otherwise
if (s.indexOf("mailto:") != -1) return;
//printout anything after http:// and the next '/'
//if no '/' then print all
if (s.indexOf('/') > -1) {
System.out.println(s.substring(0, s.indexOf('/')));
} else System.out.println(s);
}Hope this helps. I used static methods instead of encapsulating everyting into a class. -
Printing messages in Log File and Output File using Dbms_output.put_line
Hi,
I have a requirement of printing messages in log file and output file using dbms_output.put_line instead of fnd_file.put_line API.
Please let me know how can I achieve this.
I tried using a function to print messages and calling that function in my main package where ever there is fnd_file.put_line. But this approach is not required by the business.
So let me know how I can achieve this functionality.
Regards
SandyWhat is the requirement that doesn't allow you using fnd_file.put_line?
Please see the following links.
https://forums.oracle.com/forums/search.jspa?threadID=&q=Dbms_output.put_line+AND+Log+AND+messages&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
https://forums.oracle.com/forums/search.jspa?threadID=&q=%22dbms_output.put_line+%22+AND+concurrent&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein -
Reading text file and output (to stdout) a list of the unique words in the
Hi,
I have a main method as
main.java
package se.tmp;
public class Main
public static void main( String[] args )
WordAnalyzer.parse( args[0] );
and text file as
words.txt
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the quick brown fox jumps over the lazy dog
the requirement is like
I need create this WordAnalyzer class, implement the parse method, and then commit the file. This method takes a single parameter, the filename of the file to parse. The method should read this file and output (to stdout) a list of the unique words in the file along with the number of times each appears in the file.
Can anyone please help me on this?
Thanks.Where are you having problems?
-
Read from .txt file and output the content as two arrays
I am using the contoured move to control the x-y stage. The trajectory datas for x and y axis are generated using my interpolation program and it is stored in a .txt file as two columns. What I want to do is read .txt file and output the content of this file as two arrays. Is there anyone has any ideas? Thanks, the .txt file is attached.
Attachments:
R.75.txt 172 KBHi Awen,
This is quite easy to do, you can merely use the "read from spreadsheet file" function to get a 2D array (2 columns and n rows) and then use the index array function to get whatever row/colums you want..
Hope the attached VI helps you
When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
Attachments:
read sprdsheet file.vi 27 KB -
Scanning .txt file and outputting results?
Greetings Everyone. My employer has charged me with a rather
confusing task. Basically I need to scan a .txt file and retrieve
some information from it. Here is a little background on the file
itself.
This is a feed file containing the information for employees
such as name, department, employement status etc...Zeros are used
in place of spaces in this file. What I am charged with is
retrieving the employment status and name for every single person
in the file (60,000+).
I need to write a coldfusion script that can do the
following.
1. Scan a .txt file that is sent to me every night and look
for the 99th character on each line of the .txt file
2. If the 99th character is a 'T' I need to pull characters
'10-50' (which contain the name for that person).
3. Output the results of the scan to a coldfusion page
displaying the individuals' names.
If anyone out there can point me in the right direction I
would be very grateful. I've been looking for websites on this
topic but I have been unsucessful so far. Should I post this in the
advanced section of the cf forums? Once again, thank you for any
help you can give me.I guarantee you can do this! And it shouldnt be to hard so
you can breath a sigh of relief... :)
I would use <cffile action="read" file="filepath/name.txt"
variable="fileContents">
Then you should be able to do something like <cfset
fileArray = ListToArray(fileContents, "#CHR(13)##CHR(10)#")>
Now you have an array so you can loop through and try
something like the following...
<cfloop index="i" from="1" to="#ArrayLen(fileArray)#"
step="1">
<cfif fileArray
NEQ "">
<!--- Find 99th Char --->
<cfset 99thchar = Mid(fileArray, 99, 1)>
<cfif 99thchar EQ "T">
<!--- Get Name --->
<cfset empName = Mid(fileArray
, 10, 40)>
<!--- Change 0's to Spaces--->
<cfset empName = Replace(empName, "0", "#CHR(32)#")>
<cfoutput>#empName#</cfoutput><br />
</cfif>
</cfif>
</cfloop>
That should be close to what you could use... You may have to
tweak it a bit... now if it is going though 60000+ records this may
take a while...lol You might have to use the cfsetting tag to
extend the normal request timeout..
Hope this helps! -
I have been searching high and low for this one. I have a vbscript that can successfully perform the function if one file is listed. It does a Wscript.echo on the results and if I run this via command using cscript, I can output to a text file
that way. However, I cannot seem to get it to work properly if I want it to search ALL the files in the folder. At one point, I was able to have it create the output file and appear as if it worked, but it never showed any results when the script
was executed and folder was scanned. So I am going back to the drawing board and starting from the beginning.
I also have a txt file that contains the list of string text entries I would like it to search for. Just for testing, I placed 4 lines of sample text and one single matching text in various target files and nothing comes back. The current script
I use for each file has been executed with a few hundred string text lines I want it to search against to well over one thousand. It might take awhile, but it works every time. The purpose is to let this run against various log files in a folder and
let it search. There is no deleting, moving, changing of either the target folder/files to run against, nor of the file that contains the strings to search for. It is a search (read) only function, going thru the entire contents of the folder and
when done, performs the loop function and onto the next file to repeat the process until all files are searched. When completed, instead of running a cscript to execute the script and outputting the results to text, I am trying to create that as part
of the overall script. Saving yet another step for me to do.
My current script is set to append to the same results file and will echo [name of file I am searching]: No errors found. Otherwise, the
output shows the filename and the string text that matched. Because the results append to it, I can only run the script against each file separately or create individual output names. I would rather not do that if I could include it all in one.
This would also free me from babysitting it and running each file script separately upon the other's completion. I can continue with my job and come back later and view the completed report all in one. So
if I could perform this on an entire folder, then I would want the entries to include the filename, the line number that the match occurred on in that file and the string text that was matched (each occurrence). I don't want the entire line to be listed
where the error was, just the match itself.
Example: (In the event this doesn't display correctly below, each match, it's corresponding filename and line number all go together on the same line. It somehow posted the example jumbled when I listed it)
File1.txt Line 54
Job terminated unexpectedly
File1.txt Line 58 Process not completed
File1.txt
Line 101 User input not provided
File1.txt
Line 105 Process not completed
File2.txt
No errors found
File3.txt
Line 35 No tape media found
File3.txt
Line 156 Bad surface media
File3.txt Line 188
Process terminated
Those are just random fake examples for this post.
This allows me to perform analysis on a set of files for various projects I am doing. Later on, when the entire search is completed, I can go back to the results file and look and see what files had items I wish to follow up on. Therefore, the
line number that each match was found on will allow me to see the big picture of what was going on when the entry was logged.
I actually import the results file into a spreadsheet, where further information is stored regarding each individual text string I am using. Very useful.
If you know how I can successfully achieve this in one script, please share. I have seen plenty of posts out there where people have requested all different aspects of it, but I have yet to see it all put together in one and work successfully.
Thanks for helping.I'm sorry. I was so consumed in locating the issue that I completely overlooked posting what exactly I was needing help with. I did have one created, but I came across one that seemed more organized than what I originally created. Later
on I would learn that I had an error in log location on my original script and therefore thought it wasn't working properly. Now that I am thinking that I am pretty close to achieving what I want with this one, I am just going to stick with it.
However, I could still use help on it. I am not sure what I did not set correctly or perhaps overlooking as a typing error that my very last line of this throws an "Expected Statement" error. If I end with End, then it still gives same
results.
So to give credit where I located this:
http://vbscriptwmi.uw.hu/ch12lev1sec7.html
I then adjusted it for what I was doing.
What this does does is it searches thru log files in a directory you specify when prompted. It looks for words that are contained in another file; objFile2, and outputs the results of all matching words in each of those log files to another file: errors.log
Once all files are scanned to the end, the objects are closed and then a message is echoed letting you know (whether there errors found or not), so you know the script has been completed.
What I had hoped to achieve was an output to the errors.log (when matches were found) the file name, the line number that match was located on in that file and what was the actual string text (not the whole line) that matched. That way, I can go directly
to each instance for particular events if further analysis is needed later on.
So I could use help on what statement should I be closing this with. What event, events or error did I overlook that I keep getting prompted for that. Any help would be appreciated.
Option Explicit
'Prompt user for the log file they want to search
Dim varLogPath
varLogPath = InputBox("Enter the complete path of the logs folder.")
'Create filesystem object
Dim oFSO
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
'Creates the output file that will contain errors found during search
Dim oTSOut
Set oTSOut = oFSO.CreateTextFile("c:\Scripts\errors.log")
'Loop through each file in the folder
Dim oFile, varFoundNone
VarFoundNone = True
For Each oFile In oFSO.GetFolder(varLogPath).Files
'Verifies files scanned are log files
If LCase(Right(oFile.Name,3)) = "log" Then
'Open the log file
Dim oTS
oTS = oFSO.OpenTextFile(oFile.Path)
'Sets the file log that contains error list to look for
Dim oFile2
Set oFile2 = oFSO.OpenTextFile("c:\Scripts\livescan\lserrors.txt", ForReading)
'Begin reading each line of the textstream
Dim varLine
Do Until oTS.AtEndOfStream
varLine = oTS.ReadLine
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
Dim colMatches, strName, strText
Do Until oErrors.AtEndOfStream
strName = oFile2.ReadLine
objRegEx.Pattern = ".{0,}" & strName & ".{0,}\n"
Set colMatches = objRegEx.Execute(varLine)
If colMatches.Count > 0 Then
For Each strMatch in colMatches
strText = strText & strMatch.Value
WScript.Echo "Errors found."
oTSOut.WriteLine oFile.Name, varLine.Line, varLine
VarFoundNone = False
Next
End If
Loop
oTS.Close
oFile2.Close
oTSOut.Close
Exit Do
If VarFoundNone = True Then
WScript.Echo "No errors found."
Else
WScript.Echo "Errors found. Check logfile for more info."
End If
End if -
Compare data from 2 text files and output match
Hi all,
I need some advice.
Firstly in BinaryCode.txt the data is as such:
Replace BinaryCode0 1 0 0 0 0 0 0 0 0
Replace BinaryCode0 1 0 0 0 0 0 0 0 1
Replace BinaryCode1 1 1 1 0 1 1 1 1 1
Replace BinaryCode1 1 0 0 0 0 0 0 0 0
the first line in the text file is the header. So I need to check if the names in the second column (BinaryCode0 or BinaryCode1)appear in the Timed_Sets.txt file.
The data in Timed_Sets.txt is as such:
BinaryCode0,6,40,.........................
BinaryCode0,7,40,.........................
BCName1,0,20,.............................
BCName1,1,20,.............................
For example since BinaryCode0 is a match I will output the entire row in Timed_Set.txt to another array.
I have been working on a program but I don't get the expected output.
The text files and the VI are attached.
I appreciate your kind assistance in the matter.
Thank You
Regards
kart
Solved!
Go to Solution.
Attachments:
BinaryCode.txt 1 KB
compare text files.vi 15 KB
Timed_Sets.txt 2 KBIf I understood correctly what the output should be then what you basically need to do is to walk through the column in BinaryCode.txt and for each unique value pull out the corresponding rows from Timed_Sets.txt. There's a variety of ways to do this, depending on how much data you have and whether or not you can use any kind of prior knowledge as to the actual file content (such as the names of the keys being searched). Attached is one way. Modify as needed.
Attachments:
compare text files MOD.vi 27 KB -
Canon HG10 :Merging mov files and output on a Mac
Hi,
I'm on MacOSX 10.5.8 and currently working on a little video project.
I must admit my ignorance on the subject is comparable to my grandma asking how to send an email. So please be nice
I have several .mov videos imported from my Canon HG10 at the highest resolution (which according to Quicktime Movie Inspector is 1888x1062 - FPS 29.97).
Now I need to a) merge all of them into one file and b) convert the output onto a much lighter but still good quality format (H.264 mp4?).
I spent a good few hours on iMovie but since I don't need to edit the video it looked like I was pretty much wasting my time.
Could anyone give me a quick 1-2-3 on how to do the above (hopefully there's some "lamers" solution out there)?
Cheers!Here's Avids answer:
Pro50 codecs only work in Macs, so the original files need to be EXPORTED from FCP with a special codec Avid created for Mac.
So that's that issue solved ... hopefully, let's see after the next export.
But .mov files are still screwed up on my PC.
Kirk - I did reboot the machine in SafeMode, reinstalled QT, but nope - version 7.2. still doesn't play any .mov files properly that are stored on my C-drive that previously were just fine.
Thanks again. -
I want to open a txt file and output data through an AO-using DAQmx for PXI
I have a PXI running a 8145RT CPU. I have a PX6040E Multifunction DAQ card installed in the PXI. I want to program an application where I open a txt file (existing in one of the the RT machines' folders), read the first row, and output its data through an AO channel. The drivers I should use is DAQmx v7.1, and the Labview RT v.7
Any idea?What exactly are you having problems with? Reading a text file can be done a number of ways. Look at the File I/O palette and check out Read Lines From File or Read Characters From File. There are string to number conversion functions on the string palette (i.e. Scan From String). There are also numberous shipping examples on using DAQmx for analog out. If you have a specific problem or question, please post back with additional details.
-
Possible to sync multiple files and output the merged clips?
I'm working on a documentary project and have hundreds of individual clips from multiple Canon C-300 cameras and a multi-track master audio recording from a SoundDevices 744. Since this is a documentary the cameras aren't slating every take, instead they all have Lockit boxes generating timecode that is slaved to the master clock on the 744.
What I need to do it sync the pictures and the sound and output the sync'd files for screening and editorial. ScratchLab is not sync'ing the material properly but bringing a clip into Premiere is locked up without a problem.
Is there a way to sync the audio/video and output individual sync'd files using the tools in the CS6 suite? Please keep in mind that there are hundreds of individual clips so the process would have to be automated.
Cheers!That is so incredible !!!!
I also have hundred of start/stop clips with TC and audio start/stop with TC too, and I don't find a way to place the clips on the timeline at the right place of the TC.... The clips are R3D and the sound comes from a 788T. Nothing special. I work a lot with Premiere and Red and I LOVE IT.
What ? I should record audio on the Red just to permit PluralEyes to do thesync from audio ??
Please Adobe team, tell me I am sleeping and when i wake up there will be a soluce ! -
How to read file and output base64 string?
im having a hard time reading binary file and converting it to base64.
is there a parameter in extendscript like file.read('base64') ??It is possible in HTML:
var path = "/tmp/test";
result = window.cep.fs.readFile(path, cep.encoding.Base64);
if (0 == result.err) {
//success
var base64Data = result.data;
var data = cep.encoding.convertion.b64_to_utf8(base64Data);
else {
...// fail
You can also refer to the following samples for more examples:
https://github.com/Adobe-CEP/Samples/tree/master/Flickr
https://github.com/Adobe-CEP/Samples/tree/master/Collage -
Reading data in XML files and outputting information into xl spreadsheet
Can anyone help??? i want to read an XML file, and after reading the file, store certain data into a XL speadsheet. i am new to all this and dont know where to start. Can anyone provide me with coded examples or links to certain sites that can provide me with examples. I would be very grateful, thanks!!!
you will either have to use a third party toolkit or develop your own for this purpose. In case you develop your own, please be kind to share it with me ;)
I am not sure about the free ones. But Sitraka is know for developing such kits. For instance you may use sitraka's JClass which will be more then what you need. I guess JClass is free for evaluation, but you have to pay them after that.
all the best, and update this thread if you find anything for free !!
Here are some usefull inks(It seems the very first link provide some free and useful apis. Let me know, if you are able to use them)
http://www.andykhan.com/jexcelapi/
http://www.sitraka.com/software/jclass/
http://www.grapecity.com/india/Product/Database/ (From the JAva drop down, select Formula One for Java)
Rakesh
Maybe you are looking for
-
Why does photoshop elements 10 back up files in xml format
I am trying to backup my catalog including tags to my external hard drive. When I do the files are all in XML format. When I attempt to open using Photoshop i get "wrong type of file" or they are just a lot of code. What is going on. Where are the pi
-
Mail sync issue with iPhone - drains the battery
I am using microsoft webmail sync with my iPhone and lately it has started draining the phone battery (hardly stands 2 hours with full charge). I deleted the mail account from iPhone and it works fine again. Is there any settings tweak that i can try
-
Hi all , problem in copy control from billing type f2 to debit and credit
hi all, i have a problem in copy control from billing type f2 to debit and credit memos, could any body advise me the procedure for this issue , thanks , sre
-
Exise Transaction type and Document Type for part 2 record created by J2iun
Hi All , We utilized available credit of SERVICE TAX (HCESS and ECESS) and CENVAT (of both RG23A and RG23C) credit against payable SERVICE TAX ( ECESS and HCESS). At the time of save , system has generated accounting document.I have checked generate
-
Hi, How do i make the non key fields inactive after selecting the row in table control. Please tell me. Thanks, Ahmed