|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Make Multile line is one line using window Perl
Hi All I have a .csv file which is showing data as Code:
ESP Client,ESP Engagement,Misc_Projects_120101,DEFAULT,HA,Unknown,No,Unknown,201704,4.1,Unknown,AAA,Collected-Done,"she,joy.",200111,Unknown,Full Time,,Delivery_DONE AMO,Approved,2012-12-03,2012-12-06,2012-12-06,"Occupied Hours (0)",0,"Approved Hours (112)",8,"Pending Hours (0)",0,"Pending and Approved Hours (112)",8, ESP Client,ESP Engagement,Misc Projects_120101,DEFAULT,HR,Unknown,No,Unknown,201704,4.1,Unknown,AAA,Collected - Pending,"she, aj v.",200111,Unknown,Full Time,,Delivery_Pending AMO,Approved,2012-12-04,2012-12-14,2012-12-14,"Occupied Hours (0)",0,"Approved Hours (112)",8,"Pending Hours (0)",0,"Pending and Approved Hours (112)",8, I want to make in one line like using windows Perl Code:
ESP Client,ESP Engagement,Misc_Projects_120101,DEFAULT,HA,Unknown,No,Unknown,201704,4.1,Unknown,AAA,Collected-Done,"she,joy.",200111,Unknown,Full Time,,Delivery_DONE AMO,Approved,2012-12-03,2012-12-06,2012-12-06,"Occupied Hours (0)",0,"Approved Hours(112)",8,"Pending Hours(0)",0,"Pending and Approved Hours(112)",8, ESP Client,ESP Engagement,Misc Projects_120101,DEFAULT,HR,Unknown,No,Unknown,201704,4.1,Unknown,AAA,Collected - Pending,"she, aj v.",200111,Unknown,Full Time,,Delivery_Pending AMO,Approved,2012-12-04,2012-12-14,2012-12-14,"Occupied Hours(0)",0,"Approved Hours(112)",8,"Pending Hours(0)",0,"Pending and Approved Hours(112)",8, What I have tried is Code:
open('NEW',"<$new_file") || die "Error open file $new_file\n";
while (my $s2=<NEW>) {
if($s2 =~ /ESP General Client/){
if ($flag==1){
print NEW1 $new;
$flag=0;
}
my $new=$s2;
}
else{
$new .= ''.$s2;
$flag=1;
}
}
close(NEW);But its not working ---------- Post updated at 09:01 AM ---------- Previous update was at 08:59 AM ---------- Sorry the actual code I am using is open('NEW',"<$new_file") || die "Error open file $new_file\n"; while (my $s2=<NEW>) { if($s2 =~ /ESP Client/){ if ($flag==1){ print NEW1 $new; $flag=0; } my $new=$s2; } else{ $new .= ''.$s2; $flag=1; } } close(NEW); ---------- Post updated at 09:02 AM ---------- Previous update was at 09:01 AM ---------- Sorry the actual code i am using is Code:
open('NEW',"<$new_file") || die "Error open file $new_file\n";
while (my $s2=<NEW>) {
if($s2 =~ /ESP Client/){
if ($flag==1){
print NEW1 $new;
$flag=0;
}
my $new=$s2;
}
else{
$new .= ''.$s2;
$flag=1;
}
}
close(NEW);---------- Post updated at 12:24 PM ---------- Previous update was at 09:02 AM ---------- Its Make Multile line to one line using window Perl |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
The linefeeds are inside quotes, so the PERL CSV lib can pick them up, and all you need to do is replace line feed with space inside the fields.
Doing CSV in PERL without using the CSV libs seems like bad form, reinventing the wheel. If there were quoted commas in your fields, this would fall apart, so it is not robust. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Is it possible to do without CSV lib.
Everything is Possible in Perl |
|
#4
|
|||
|
|||
|
Possible, of course, but it smacks of intellectual laziness, lack of desire to learn or reuse. Perhaps API specs confuse him. Next!
![]() |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Can you please find the error, in above code. I think with some tweaking in the above code , it will start working.
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Code:
perl -lne "$line=$line.' '.$_;if(/^$/ or eof){print $line;undef $line;}" your_fileRegards, Vijay Last edited by Scott; 12-30-2012 at 12:42 AM.. Reason: Removed link |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Finally this thread ends up with this working code Code:
my $new='';
$flat_file='flat_file.csv';
$new_file='new_file.csv';
open('NEW',"<$new_file") || die "Error open file $new_file\n";
open('NEW1',">$flat_file") || die "Error open file $flat_file\n";
while (my $s2=<NEW>) {
chomp($s2);
if($s2 =~ /ESP Client/){
print NEW1 "$new\n"; $new='';
$new=$s2;
}
else{
$new = $new.$s2;
}
}
close(NEW);
close(NEW1); |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PERL or SHELL Scrript to search in Directories by taking line by line from a text file | pasam | Shell Programming and Scripting | 9 | 12-29-2011 02:30 AM |
| How to use Perl to join multi-line into single line | happyday | Shell Programming and Scripting | 5 | 11-10-2009 01:44 AM |
| How to use Perl to merge multi-line into single line | happyday | Shell Programming and Scripting | 3 | 05-11-2009 04:42 AM |
| make multiple line containing a pattern into single line | VTAWKVT | Shell Programming and Scripting | 13 | 12-04-2008 05:40 PM |
| Multile Pattern Search in a same line and delete | sasree76 | Shell Programming and Scripting | 2 | 04-16-2008 02:12 PM |
|
|