How can I return all line in a file that matches using regexp
Hi!
I want to return whole line from a file. This lines must to contains matches for a pattern.
How Can I do this.
I make some samples, but only return the matches segment of the line.
Sample code to look for 00:00
If I put .*00:00.* in the pattern this return whole line, but is to slow in this file about 300,000 lines.
If I put just 00:00 in the pattern only return the 00:00, but so fast.
What can I Do, or I must use indexOf in a sequential read?
try {
// Create matcher on file
Pattern pattern = Pattern.compile(".*00:00.*");
Matcher matcher = pattern.matcher(fromFile("logusers_0712"));
// Find all matches
while (matcher.find()) {
// Get the matching string
String match = matcher.group();
//Here I display the matches
System.out.println(match);
} catch (IOException e) {
e.printStackTrace();
}Thanks in advance
My two cents:
Grep is a Bad Idea (TM). It is not java and itties
es the solution to a the operational system.Not necessarily bad. Like you say--we don't know much
about the OP's requirements, so grep may be just
fine.
!java != badYour assertion is true. But creating an solution tied to the system when you can do it pure java does not seem like a good Idea especially when we not even know which system he is using. What if he is using Windows or MacOS? Sure he can use grep on non *nix systems, but that would fore him to install the necessary tools, making his solution even more complex.
>
About using indexOf, it is a little limited, not
ot knowing what exactly the OP is searching for itis
difficult to say if it is enough. RegEx would workin
both ways.He said he was searching for "00:00". I think that was just a sample. He apears to be scanning a log file as far as I understood. 00:00 could be a timestamp for whose he wants to see the entries. Using a RegEx make the job easier, like "01:\\d{2} am" to get the whole range of entries inside that morning hour.
If it's really
that literal string he needs to match, as opposed to
say "\\d\\d:\\d\\d" then indexOf is simpler. It will
probably perform better too. I don't know if that
difference will be significant, but on a file of
300,000 lines, it might be noticable.The only way to know that is testing both solutions. But you are right, we are just wondering here, with no better info on the requirements anything can go. I agree with you, indexOf is the simple way to go and probably will sufice.
May the code be with you.
Similar Messages
-
How can i return object from oracle in my java code using pl/sql procedure?
How can i return object from oracle in my java code using pl/sql procedure?
And How can i returned varios rows fron a pl/sql store procedure
please send me a example....
Thank you
nullyes, i do
But i can't run this examples...
my problem is that i want recive a object from a PL/SQL
//procedure callObject(miObj out MyObject)
in my java code
public static EmployeeObj callObject(Connection lv_con,
String pv_idEmp)
EmployeeObj ret = new EmployeeObj();
try
CallableStatement cstmt =
lv_con.prepareCall("{call admin.callObject(?)}");
cstmt.registerOutParameter(1, OracleTypes.STRUCT); // line ocurr wrong
//registerOutParameter(int parameterIndex, int sqlType,String sql_name)
cstmt.execute();
ret = (EmployeeObj) cstmt.getObject(1);
}//try
catch (SQLException ex)
System.out.println("error SQL");
System.out.println ("\n*** SQLException caught ***\n");
while (ex != null)
System.out.println ("SQLState: " + ex.getSQLState ());
System.out.println ("Message: " + ex.getMessage ());
System.out.println ("Vendor: " + ex.getErrorCode ());
ex = ex.getNextException ();
System.out.println ("");
catch (java.lang.Exception ex)
System.out.println("error Lenguaje");
return ret;
Do you have any idea? -
How can I block all other mail account just to only use the exchange mailbox of our company? This is to prevent the user to setup his on company iPhone.
I don't know if I'm asking this all in a way that can be understood? Thanks ED3K, however that part I do understand (in the link you provided!)
What I need to know is "how" I can separate or rather create another Apple ID for my son-who is currently using "my Apple ID?" If there is a way to let him keep "all" his info on his phone (eg-contacts, music, app's, etc.) without doing a "reset?') Somehow I need to go into his phone's setting-create a new Apple ID and possibly a new password so he can still use our combined iCloud & Itunes account?
Also then letting me take back my Apple ID & password, but again allowing us (my son and I) to use the same iCloud & Itunes account? Does that make more sense??? I'm sincerely trying to get this cleared up once and for all----just need guidance from someone who has a true understanding of the whole Apple iCloud/Itunes system!
Thanks again for "anyone" that can help me!!! -
How can I install all my music and movies that I bought into my computer?
How can I install all the musics and movies that I bought from iTunes into my computer?
iTunes Store: Transferring purchases from your iOS device or iPod to a computer - http://support.apple.com/kb/HT1848 - only purchases from iTunes Store
-
How can I download all my raw+jpg files from new Canon SX50 HS camera?
How can I download all my raw+jpg files from new Canon SX50 HS camera? Some work and most won't.
Are you running Lightroom 4.3 which is the minimum version required for that camera?
http://helpx.adobe.com/creative-suite/kb/camera-raw-plug-supported-cameras.html -
How can I know the name of the file that the user has currently open ?
Hello
I'm developing a module for x3dv.
http://hiperia3d.blogspot.com/search/label/X3DV%20Module%20For%20Netbeans
I am going to add a button to open the files when I click it.
I just need to know how can I know the name of the file that the user has currently open in the editor. What variable holds it in Netbeans?
Thank you
JordiIf you are using the JFileChooser to open the document, I would create another class with this included:
//initiate class variables
private File f;
//create JFileChooser
JFileChooser fc = new JFileChooser();
fc.setMultiSelectionEnabled(false);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY)
//set the chooser to initialise File f with the file selected
int status = fc.showOpenDialog(null);
if (status == JFileChooser.APPROVE_OPTION)
f = fc.getSelectedFile();
public File getFile()
return f;
} -
My kids desabled my mini ipad after several tries to log in. My computer that I used to sincronize it doesn't work anymore and i can't connected to itunes.. How can i restart it without the actual computer that I used before??
You can use any computer but your data will be lost if you have no backup.
-
I am not able to Sync. My iPOD classic 80Gb. It tells that as iTunes can not read the contents-restore to factory settings- after restoring – it tells that it can not be restored bcause there are files that are used by other application. My iPOD appears in My Computer in drive H as a mass storage generick volume
Try disabilng the Enable Disk Use option from under the iPod's Summary tab, applying the changes, and seeing if that helps.
Otherwise, temporarily disabling any antivirus, security, firewall, or file indexing software that may be running on your system and then try restoring your iPod again.
B-rock -
Hi,
I'm using FM F4IF_INT_TABLE_VALUE_REQUEST to show a pop-up with my internal table values. The internal table has 3 fields, ATINN, ATZHL and a description field ATWTB. ATINN and ATZHL are needed to complete the unique table key, however this FM will only return the value of one field in any line I select.
How can I see all the values in the line I select in the return table?
My code is as follows:
DATA: tbl_cawnt LIKE cawnt OCCURS 0,
wa_cawnt LIKE cawnt,
BEGIN OF tbl_list OCCURS 0,
atinn LIKE cawnt-atinn,
atzhl LIKE cawnt-atzhl,
atwtb LIKE cawnt-atwtb,
END OF tbl_list,
wa_list LIKE tbl_list,
tbl_return LIKE ddshretval OCCURS 0,
wa_return LIKE ddshretval,
tbl_fields LIKE dfies OCCURS 0,
tbl_dynp LIKE dselc OCCURS 0.
REFRESH: tbl_list, tbl_cawnt.
SELECT atinn atzhl atwtb
FROM cawnt
INTO CORRESPONDING FIELDS OF TABLE tbl_cawnt
WHERE spras EQ sy-langu.
LOOP AT tbl_cawnt INTO wa_cawnt.
CLEAR wa_list.
MOVE: wa_cawnt-atwtb TO wa_list-atwtb,
wa_cawnt-atinn TO wa_list-atinn,
wa_cawnt-atzhl TO wa_list-atzhl.
APPEND wa_list TO tbl_list.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'ATWTB'
dynpprog = sy-repid
dynpnr = sy-dynnr
value_org = 'S'
TABLES
value_tab = tbl_list
return_tab = tbl_return
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Thanks!Hi,
Use the structure DYNPFLD_MAPPING
With this internal table you can easily define that you want to return
other columns of the hit list in addition to field RETFIELD to the
screen.
In this IT you can MAP the screen fields to the serch help screen fields this has three fields
FLDNAME this is the field anme from the search help
FLDINH This has to be blank which would be field with the field value that you want to map
DYFLDNAME THis is the screen field name.
So here you can get the values for the other fields that you want which are on the search help just populate the name of the fields in FLDNAME.
Regards,
Himanshu -
How can I add all of my PDF files at once
Is there any way to add all of my PDF files that are in different folder at once, kind of self search option that add the files automatically, thanks.
I'd also really like this feature added (unless I'm just missing something that is)
-
Can anyone tell me how to return all my print settings to original default?
To downgrade to Firefox 3.6 first uninstall Firefox 4, but do not select the option to "Remove my Firefox personal data". If you select that option it will delete your bookmarks, passwords and other user data.
You can then install the latest version of Firefox 3.6 available from http://www.mozilla.com/en-US/firefox/all-older.html - it will automatically use your current bookmarks, passwords etc.
To avoid possible problems with downgrading, I recommend going to your profile folder and deleting the following files if they exist - extensions.cache, extensions.rdf, extensions.ini, extensions.sqlite and localstore.rdf. Deleting these files will force Firefox to rebuild the list of installed extensions, checking their compatibility, and reset toolbar customizations.
For details of how to find your profile folder see https://support.mozilla.com/kb/Profiles -
How can i get all java class names from a package using reflection?
hi,
can i get all classes name from a package using reflection or any other way?
If possible plz give the code with example.You can't, because the package doesn't have to be on the local machine. It could be ANYWHERE.
For example, via a URLClassLoader (ie from the internet) I could load a class called:
com.paperstack.NobodyExpectsTheSpanishInquisitionI haven't written it yet. But I might tomorrow. How are you going to determine if that class is in the package?
This subject comes up a lot. If you want to do something a bit like what you're asking for (but not quite) there are plenty of threads on the subject. Use google and/or the forum search facility to find them.
But the answer to your question, as you asked it, is "you can't do that". -
Hello somebody can help me? I bought a new ipad and I need to transfer all the information, documents, etc.. from my old ipad to the new one how can I do that?
You need to back up your current iPad either to your computer, or if you are on the cloud to the cloud. Then when you go to set up your new iPad, you'll either restore it from the computer (iTunes backup) or if you back up to the cloud, wirelessly from the cloud. The new device will give you the option to restore from a cloud backup if you are using the cloud.
-
How can I import data from a csv file into databse using utl_file?
Hi,
I have two machines (os is windows and database is oracle 10g) that are not connected to each other and both are having the same database schema but data is all different.
Now on one machine, I want to take dump of all the tables into csv files. e.g. if my table name is test then the exported file is test.csv and if the table name is sample then csv file name is sample.csv and so on.
Now I want to import the data from these csv files into the tables on second machine. if I've 50 such csv files, then data should be written to 50 tables.
I am new to this. Could anyone please let me know how can I import data back into tables. i can't use sqlloader as I've to satisfy a few conditions while loading the data into tables. I am stuck and not able to proceed.
Please let me know how can I do this.
Thanks,
ShilpiWhy you want to export into .csv file.Why not export/import? What is your oracle version?
Read http://www.oracle-base.com/articles/10g/oracle-data-pump-10g.php
Regards
Biju -
How can I copy the name of a file, that I selected by a click?
Hi,
I have a device controled by a Excell (VBA) interface. Truogh this interface I control the motors and Diadem (for the report) and the data are save in a database. When I use the load button from the excell, the VBA application call the script from Diadem Load_DATA_BOF.VBS, (after I complete the new data for the report), and make the report. Now to make it work, I copy the name of the filename that I want to load in a TextBox, and all the data are store in a txt file( protocol_for_load.txt) and Diadem takes from there the data for the report.
What I want to do is to fill automatic the field of the filename in the protocol_for_load.txt, when I select the file in Diadem.
Can this be done?
Thank you for your time
Solved!
Go to Solution.
Attachments:
BOF script.zip 177 KBHi Brad,
I find out how to copy the name of a selected file ( with filedlgfile) and now I want to open the text file ( with the name the same like the file loaded) so I can read the data from inside, but the command textfileopen from the script can't support a variable in the description, I thing.
Fno = textfileopen ( filenametxt, tfread)
Please look in to my script to understand better.
I need to open the txt file with the name the same like the file loaded, to take the data and fill the report. This I need to do in Diadem Script, because I will call the script trough a VBA interface.
Sorry for not being more clearly first time, but I am a beginner in working with VBS.
Attachments:
Diadem script.zip 69 KB
Maybe you are looking for
-
PL/SQL Exception for ORA-00942 - Table or view not found?
Hey there! I want to create an exception my code runs into whenever it tries to select from a table that is not existent (or because of insufficient privileges). How can I get these ORA-00942 errors and place them into a exception? Except for WHEN OT
-
When starting iTunes I continually get an error message " The registry Settings used by the iTunes drivers for importing and burning CDs and DVDs are missing. This can happen as a result of installing other CD burning software. Please reinstall iTun
-
Tax classification for sales order before ECC
Hi expert, We have recently upgraded from 4.6C to ECC6.0 and noticed the following issue, please kindly advise. Thanks. The tax classification for one of the regular customer has always been maintained as '0' (Tax Exempt). In 4.6C, in the sales order
-
Obsolete ABAP statements/FM/BAPI in sap 4.7
dear experts pls gv me the details of obsolete ABAP statements/FM/BAPI in sap 4.7 and their replacement in ECC 6.0,the statements should be related to MODULE POOL ,reports
-
Help me, I can't send text messages to some people. I had this problem since I upgraded to software version 3. I'm sick of using an another phone