473,382 Members | 1,441 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,382 software developers and data experts.

Perl Help

I have a unix file:

file contents:

foo.text:

s_map_test
$$param_name_20070919112345

I want to extract only the 2nd part of the line, and write to new file - foo.out

The New file should have:

foo.out:
20070919112345

Thanks for help
Sep 19 '07 #1
4 1174
numberwhun
3,509 Expert Mod 2GB
I have a unix file:

file contents:

foo.text:

s_map_test
$$param_name_20070919112345

I want to extract only the 2nd part of the line, and write to new file - foo.out

The New file should have:

foo.out:
20070919112345

Thanks for help
Will all of the data in your source file have the same format for the data? ($$param_name_20070919112345) In other words, will there be the two underscores everytime or will it vary? Can you provide a sample of several lines so we can possibly see the pattern?

Thanks!

Regards,

Jeff
Sep 19 '07 #2
Will all of the data in your source file have the same format for the data? ($$param_name_20070919112345) In other words, will there be the two underscores everytime or will it vary? Can you provide a sample of several lines so we can possibly see the pattern?

Thanks!

Regards,

Jeff
------------------------------------------

Jeff,

the file is going to be generated on Ad-hoc basis daily.

todays file:

s_map_test
$$paramname_20070919112345

out file: 20070919112345

Tommorows file:

s_map_test
$$paramname_20070920112346

out file:

20070920112346

Note: there is only one underscore (_), instead of two.

I just need the numeric portion from 2nd line in the source file, and write it to a new file.

Thanks a lot
Sandy
Sep 19 '07 #3
numberwhun
3,509 Expert Mod 2GB
------------------------------------------

Jeff,

the file is going to be generated on Ad-hoc basis daily.

todays file:

s_map_test
$$paramname_20070919112345

out file: 20070919112345

Tommorows file:

s_map_test
$$paramname_20070920112346

out file:

20070920112346

Note: there is only one underscore (_), instead of two.

I just need the numeric portion from 2nd line in the source file, and write it to a new file.

Thanks a lot
Sandy
Normally we would want to see your code before providing you any, but I am in a code generating mood at the moment. See if the following does what you want:

The data I used was:

paramname_20070920112346

I took off the $$ at the beginning, assuming that they would not be there. If they are, you can modify the regex to include them.

Here is the code I used:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. open(DATA, "<data.txt");
  5.  
  6. while(<DATA>)
  7. {
  8.     if($_ = m/\D+\_(\d+)$/)
  9.     {
  10.         print("The number is:  $1\n");
  11.     }
  12.     else
  13.     {
  14.         print("Regex didn't find anything!\n");
  15.     }
  16. }
  17.  
Regards,

Jeff
Sep 19 '07 #4
Normally we would want to see your code before providing you any, but I am in a code generating mood at the moment. See if the following does what you want:

The data I used was:

paramname_20070920112346

I took off the $$ at the beginning, assuming that they would not be there. If they are, you can modify the regex to include them.

Here is the code I used:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. open(DATA, "<data.txt");
  5.  
  6. while(<DATA>)
  7. {
  8.     if($_ = m/\D+\_(\d+)$/)
  9.     {
  10.         print("The number is:  $1\n");
  11.     }
  12.     else
  13.     {
  14.         print("Regex didn't find anything!\n");
  15.     }
  16. }
  17.  
Regards,

Jeff
-----------------------------

Thanks jeff
Sep 19 '07 #5

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

Similar topics

3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
4
by: Firewalker | last post by:
Hey guys, I am newbie to perl. I am trying to deal with dates ( such trying to find what the date would be after month). Is therea function or date class( I am a java programmer, I couldnt find...
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
2
by: shruti | last post by:
hiii all I'm tryin to call a perl script from a C program in following 2 ways- 1.By callin system function. But there's some problem because the system function is not able to executeany...
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.