473,804 Members | 3,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I need help to filter a text file.

5 New Member
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 1482
docsnyder
88 New Member
@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 Recognized Expert Specialist
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
1283
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
2262
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 version="1.0" encoding="UTF-8"?> <Message id="100199" version="1.9" something="1"> <Jobs id="999" priority="0">
2
3557
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 one) after the dialog is dismissed. Any hint is highly appreciated! Leo OPENFILENAME ofn; TCHAR defDir; TCHAR filePath;
8
6101
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 only the files I want to see appear in the file list box. When I change the filter to one of the other filters, all the files in the list disappear. If I then manually type a filter into the "Filename" textbox, then the files appear and the filter...
3
5619
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 want to give them the opportunity to run these modules from home as well, we are trying to get the USERNAME/COMPUTERNAME as well, so the students, when they sign up for the modules, they can ONLY run the modules fromhome PC. We found a nice...
15
2059
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 or by the below program It lets you place a palette from a file or from a program on the clipboard and allows you to retrieve one from the clipboard. But you'll find the retrieved one is always "Nothing"
5
2461
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 filter on 5 fields in this table, and can include as many field values as s/he needs. The popup is reached from a command button on the main form : This button is on the main form, Datasystem:
1
1422
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 as to get basic re-direction and piping working. The only problem I have is when the user decides not to use re-direction, or a file, and instead they decide to enter text directly in the Terminal. I have this loop for looping through a...
1
2259
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 "No Filter defined for the PDF file", So how can we define the Filter for PDF file, so that iFilter can extract it's text. Thanks in advance,
8
4104
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 just the ones that I want. I used the statement before and though it displays the *.csproj files it does not display the *.sln files. openFileDialog.Filter = "Solution Files (*.sln) And Project Files (*.csproj)|*sln ;*.csproj|All Files...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9152
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.