473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I need help to filter a text file.

i have a file:

date: 02-02-2006
name: geopar
doc: test machine
username: test1
password: p4ss
address: test2
phone: 343534543535
username: test
fax: 453453534
etc.....

i want to generate a new file with data : (username password)

(a script to check for structure
username:
password:
in file, and if found dump username & password to outfile..)

help :)
Feb 12 '07 #1
2 1462
@superc0red

The basic idea is:
Expand|Select|Wrap|Line Numbers
  1. @file = (
  2.   "date: 02-02-2006",
  3.   "name: geopar",
  4.   "doc: test machine",
  5.   "username: test1",
  6.   "password: p4ss",
  7.   "address: test2",
  8.   "phone: 343534543535",
  9.   "username: test",
  10.   "fax: 453453534",
  11.   "",
  12.   "date: 02-02-2006",
  13.   "name: geopar",
  14.   "doc: test machine",
  15.   "username: test2",
  16.   "password: p5ss",
  17.   "address: test2",
  18.   "phone: 343534543535",
  19.   "username: test",
  20.   "fax: 453453534",
  21. );
  22.  
  23. for $line ( @file ) {
  24.   if ( $line =~ m/^username:\s+(.*)$/ ) {
  25.     $user = $1;
  26.   }
  27.   elsif ( $line =~ m/^password:\s+(.*)$/ ) {
  28.     $pw = $1;
  29.  
  30.     printf("$user $pw\n");
  31.  
  32.     $user = $pw = undef;
  33.   }
  34. }
Reading in the input file and writing the result to the output file instead of printing it is left to you as an exercise ;o)

Greetz, Doc
Feb 12 '07 #2
KevinADC
4,059 Expert 2GB
i have a file:

date: 02-02-2006
name: geopar
doc: test machine
username: test1
password: p4ss
address: test2
phone: 343534543535
username: test
fax: 453453534
etc.....

i want to generate a new file with data : (username password)

(a script to check for structure
username:
password:
in file, and if found dump username & password to outfile..)

help :)
Do you have any existing code? If so maybe it just needed a small tweak to work. If not, Docs suggestion should get you over the hump.
Feb 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: mcc | last post by:
When i put these two java scripts in the same html file only the fade script works. Why is that??? this part is in the <head>
2
by: Thomas | last post by:
Hi, I used xsd.exe to generate a *.xsd file from the *.xml-File and then I created a typed DataSet in VisualStudio 2003 But now I have problems to read the data from the DataSet. <?xml...
2
by: Leo | last post by:
I am using OPENFILENAME and GetSaveFileName to let user save a document out. However, the default name won't show up in the dialog and the selected filter can't be obtained (always got the default...
8
by: marcus.kwok | last post by:
I am having a weird problem and I have can't figure out why it is happening. I create an OpenFileDialog and set a filename filter. When the dialog first opens, the filter works correctly, and...
3
by: sunbeam | last post by:
Short Description of the Project: we developed a e-learning system for our students. each student has a unique username/password to view the modules he/she should view and nothing more. since we...
15
by: active | last post by:
Below is a small but complete program that appears to show you can't retrive a Palette from the clipboard. This is true whether the palette is placed on the clipboard by Photoshop or Photoshop...
5
by: Thelma Roslyn Lubkin | last post by:
I am still having trouble trying to use a popup form to allow user to set filters for the main form. The main form is based on a single table. The popup contains 5 listboxes, so the user can...
1
by: Gotejjeken | last post by:
I am currently working on an email filter, and it will either get input from a file and then filter junk mail out, or get mail from cin. I have the file part working correctly, and I even got as far...
1
by: my4color | last post by:
Hello everyone, we are creating the PDF file using the iTextSharp. After creating that file we are using the Acrobat's iFilter for extracting text from that PDF file. But we get the exception...
8
by: Z.K. | last post by:
I would like to display two different types of files when bringing up the OpenFileDialog, but I can't seem to figure out how to do this. I can manage a single file type or all file types, but not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.