Maybe I´m too old for perl/awk/sed, too young to stop programming. Here is the problem I need to solve:
I have info like this in a TXT file:
Name:
Name 1
Phone:
1111111
Email:
some@email1
DoentMatterInfo1:
whatever1
=
Name:
Name 2
Phone:
22222222
DoentMatterInfo2:
whatever2
Email:
some@email2
=
Name:
Name 3
DoentMatterInfo3:
whatever2
Email:
some@email3
=
Please note that the desired info is in the next line, there is a record separator (=) and very important, some records doesn't have all the info, but could have info that we dont want.
So, the challenge is to extract the desired info, if exist, in an output like:
Name 1 ; 111111 ; some@email1
Name 2 ; 222222 ; some@email2
Name 3 ; ; some@email3
What I have tried that worked a little bit but stills is not what I´m looking for.
1. Using PERL
Using Perl I got the fields that matter:
while (<>) {
if ($_ =~ /Name/) {
print "=\n". scalar <>;
}
if ($_ =~ /Email/) {
print "; ". scalar <>;
}
if ($_ =~ /Phone/) {
print "; ". scalar <>;
}
}
The I got a file like:
Name 1
; 1111111
; some@email1
=
Name 2
; 22222222
; some@email2
=
Name:
Name 3
; some@email3
=
Now with sed I put each record in a single line:
SED
With SED, this command replaces the Line Feed, got the info in a single line:
sed ':a;N;$!ba;s/\n//g' input.txt > out1.txt
And out back the line feed:
sed 's/|=|/\n/g' out1.txt > out2.txt
So I got a file with the info in each line:
Name 1 ; 1111111 ; some@email1
Name 2 ; 22222222 ; some@email2
Name 3 ; some@email3
Still not what I would like to get from coding. I want something better, like being able to fill the missing phone with space, so the second column could be always the phone column. Do you get it?
AS you can see, the poitn is to find a solution, no matter if is using Perl, AWk or SED. I´m trying perl hashes...
Thanks in advance!!