I have a CSV file which contains number series as one of the fields. Some of the records of the field look like :
079661/3
I have to convert the above series as
079661
079662
079663
and store it as 3 different records.
Looking for help on how to achieve this. Am a newbie at Shell scripting.
Thanking all in advance for the help..
Mihir
5 2475 arne 315
Expert 100+
I have a CSV file which contains number series as one of the fields. Some of the records of the field look like :
079661/3
I have to convert the above series as
079661
079662
079663
and store it as 3 different records.
Looking for help on how to achieve this. Am a newbie at Shell scripting.
Thanking all in advance for the help..
Mihir
What does the syntax x/y mean?
- the (y-1) next higher numbers, e.g.
123,4
123
124
125
126
- the next numbers until the numbers end with the same digit
123,4
123
124
- can y have multiple digits, like
123,30
123
124
125
...
129
130
?
You'll have to describe the problem a little bitmore detailed in order to get accurate solutions, I guess.
And: this must be written in bash or can you use other tools like perl?
arne
Hi arne,
Following is the clarification sought by you:-
x/y means:
the next numbers until the numbers end with the same digit
123,4
123
124
Also there will not be multiple digits. Even perl can be used.
Thanks,
Mihir
arne 315
Expert 100+
Hi arne,
Following is the clarification sought by you:-
x/y means:
the next numbers until the numbers end with the same digit
123,4
123
124
Also there will not be multiple digits. Even perl can be used.
Thanks,
Mihir
This should do more or less what you want: -
#!/usr/bin/perl
-
-
if (2 != ($#ARGV+1)) {
-
-
print "Usage: $0 <infile> <outfile>\n";
-
exit 1;
-
}
-
-
open INFILE, "<$ARGV[0]" || die "unable to open INFILE";
-
open OUTFILE, ">$ARGV[1]" || die "unable to open OUTFILE";
-
-
while (<INFILE>) {
-
-
if (/(.*)(\d)\/(\d)/) {
-
-
my $stub = $1;
-
my $start = $2;
-
my $end = $3;
-
-
for $i ($start..$end) {
-
-
print OUTFILE "$stub$i\n";
-
}
-
-
} else {
-
-
print OUTFILE "$_";
-
}
-
}
-
-
close INFILE;
-
close OUTFILE;
-
HTH,
arne
Thanks a lot...the script does more or less what I want....
But am a newbie to perl...Can you please explain what
(/(.*)(\d)\/(\d)/ does and how are you seperating the string into 3 variables by using the regular expression??
Thanks again..
Mihir
arne 315
Expert 100+
Thanks a lot...the script does more or less what I want....
But am a newbie to perl...Can you please explain what
(/(.*)(\d)\/(\d)/ does and how are you seperating the string into 3 variables by using the regular expression??
Thanks again..
Mihir
The regex is enclosed by forward slashes, '.' is an arbitrary symbol, '*' means an arbitrary number, so we have an arbitrary number of arbitrary symbols in the first pair of brackets. \d is a digit, the \ is an escape character for the /, which is taken as a symbol (and not the end of the regex!), then we have another digit. The brackets group the single elements and can be referred to by $n, where n denotes the number of the bracket pair. So, if a line contains 2 digits separated by a / and preceeded by something else, we expand it.
HTH,
arne
Sign in to post your reply or Sign up for a free account.
Similar topics
by: burn_hall |
last post by:
Hi,
I have a problem and can't figure it out and need your help, please
look at the following code and the output also a xml file snippet is
down there too.
Looking at the output I don't know why...
|
by: Cigdem |
last post by:
Hello,
I am trying to parse the XML files that the user selects(XML files are
on anoher OS400 system called "wkdis3"). But i am permenantly getting
that error:
Directory0: \\wkdis3\ROOT\home...
|
by: wukexin |
last post by:
Help me, good men. I find mang books that introduce bit "mang header
files",they talk too bit,in fact it is my too fool, I don't learn it, I have
do a test program, but I have no correct doing...
|
by: ralphNOSPAM |
last post by:
Is there a function or otherwise some way to pull out the target text
within an XML tag?
For example, in the XML tag below, I want to pull out 'CALIFORNIA'.
...
|
by: sommarlov |
last post by:
Hi everyone
>From one of our systems an xml file is produced. I need to validate
this file before we send it to an external system for a very lenghty
process. I cannot change the xml file layout....
|
by: syhzaidi |
last post by:
How can we do Parsing of Hexdecimel in C# reading string from stream file for eg..
i have a file like..........
0f 2f 12 2d 3a.......in hexa decimal save in a file.txt and i m reading it from...
|
by: Paulers |
last post by:
Hello,
I have a log file that contains many multi-line messages. What is the
best approach to take for extracting data out of each message and
populating object properties to be stored in an...
|
by: savj14 |
last post by:
I have been driving myself crazy the past few days trying to figure this out. I have tried different Parsing Scripts and have read and searched various things trying to find a solution. I am...
|
by: Ahmed, Shakir |
last post by:
Thanks everyone who tried to help me to parse incoming email from an exchange server:
Now, I am getting following error; I am not sure where I am doing wrong. I appreciate any help how to resolve...
|
by: Damien87 |
last post by:
Hi,
I have a .data file which is essentially just a text file with a bunch of numbers.
It's in the format "xx yy zzz abc
ccf fffd sss xxx
xx sss qq"
Basically it is a random amount of numbers...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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,...
|
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...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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: 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...
| |