from this file I have to split the fields on basis of comma"," however, I the data present inside double qoutes should be treated as 1 field
for this I have written the below code
Code:
$ cat ./prog
#!/usr/bin/perl -w
use strict;
while (<>)
{
my @arr=split(',',$_);
my $startpos;
my $endpos;
#determining sarting and ending position of the quotes
for(my $i=0;$i<@arr;$i++)
{
$startpos=$i if ( $arr[$i] =~ /^( *)"/ );
$endpos=$i if ( $arr[$i] =~ /"( *)$/ );
}
#clubiing the elemnts between Starting and ending quotes in one element and removing redundant entities
for (my $i=0; $i<@arr; $i++)
{
if ( defined($startpos) && $i == $startpos )
{
for ( my $j=$startpos+1; $j <=$endpos;$j++)
{
$arr[$i] .= ",".$arr[$j];
$arr[$j] = undef;
}
}
}
#removing undef entities from the array
@arr=grep defined, @arr;
for(my $i=0;$i<@arr;$i++)
{
print "\$arr[$i] = "."$arr[$i]"."\n";
}
}
this is working fine except for the last line of input file
Code:
no, "good,morning", yes, "good , afternoon"
Current output
Code:
$ ./prog infile
$arr[0] = hi
$arr[1] = i
$arr[2] = "am , sam"
$arr[3] = y
$arr[0] = hello
$arr[1] = good
$arr[2] = morning
$arr[0] = abcd
$arr[1] = " ef, gh "
$arr[2] = ij
$arr[0] = no
$arr[1] = "good
$arr[2] = morning"
$arr[3] = yes
$arr[4] = "good , afternoon"
Expected output
Code:
$ ./prog infile
$arr[0] = hi
$arr[1] = i
$arr[2] = "am , sam"
$arr[3] = y
$arr[0] = hello
$arr[1] = good
$arr[2] = morning
$arr[0] = abcd
$arr[1] = " ef, gh "
$arr[2] = ij
$arr[0] = no
$arr[1] = "good,morning"
$arr[2] = yes
$arr[3] = "good , afternoon"
I'm having a strange problem with escaping double-quotes. I have a script that looks like this:
#!/bin/bash
for HOST in `cat $INFILE | grep -v ^#`
do
for VFILER in `some_command`
do
echo " "
echo -e '\E
The problem with ssh command... (3 Replies)
I have a csv file with lines like the followings
123456,"ABC CO., LTD","XXX"
789012,"DEF LIMITED", "XXX"
before I bcp this file to database, the comma in "CO.," need to be removed first.
My script is cat <filename> | sed 's/"CO.,"/"CO."/g'
but it doesn't work. Can anyone here able to... (2 Replies)
Hi,
I have a requirement to replace the comma's inside the double quotes. The comma's inside the double quotes will get changed dynamically.
Input Record:
"Washington, DC,Prabhu,aju",New York
Output Record:
"Washington| DC|Prabhu|aju",New York
I tried with the below command but it... (3 Replies)
Hi,
my requirement is to find the count of commas in a string excluding the ones in double quotes.
For example:
If the input string is
abc,xyz.com,lmhgdf,"abc, 401 street","tty,stt",45,23,45
The output should be 7 (7 Replies)
Hello experts,
I need to validate a csv file which contains data like this:
Sample.csv
"ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0
"ABCD","I",23,0,9,,"23/12/2012","OK","Street,State, 91135",0
I just need to check if all the records contain exactly the number of... (5 Replies)
Okay, I would like to delete all the commas in a .CSV file (TEST.CSV) or at least substitute them with empty space, that are enclosed in double quote.
Please see the sample file as below:
column 1,column 2,column 3,column 4,column 5,column 6,column 7,column 8,column 9,column 10... (8 Replies)
Hello to all,
I'm trying to match only fields surrounded by double quotes that have one or more commas inside.
The text is like this
"one, t2o",334,"tst,982-0",881,"kmk 9-l","kkd, 115-001, jj-3",5
The matches should be
"one, t2o"
"tst,982-0"
"kkd, 115-001, jj-3"
I'm trying with... (11 Replies)
i have data as below
123,"paul phiri",paul@yahoo.com,"po.box 23, BT","Eco Bank,Blantyre,Malawi"
i need an output to be
123,"paul phiri",paul@yahoo.com,"po.box 23 BT","Eco Bank Blantyre Malawi" (5 Replies)
Hi All,
I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes.
Sample Data :
"221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Please use code tags
Hi,
I have input data is below format and n of column in the multiple flat files. the string data has any double quotes(") values replaced to double double quotes for all the columns{"").
Also, my input flat file each column string data has carriage of new line too.... (14 Replies)
Discussion started by: SSrini
14 Replies
LEARN ABOUT DEBIAN
io::async::protocol::linestream
IO::Async::Protocol::LineStream(3pm) User Contributed Perl Documentation IO::Async::Protocol::LineStream(3pm)NAME
"IO::Async::Protocol::LineStream" - stream-based protocols using lines of text
SYNOPSIS
Most likely this class will be subclassed to implement a particular network protocol.
package Net::Async::HelloWorld;
use strict;
use warnings;
use base qw( IO::Async::Protocol::LineStream );
sub on_read_line
{
my $self = shift;
my ( $line ) = @_;
if( $line =~ m/^HELLO (.*)/ ) {
my $name = $1;
$self->invoke_event( on_hello => $name );
}
}
sub send_hello
{
my $self = shift;
my ( $name ) = @_;
$self->write_line( "HELLO $name" );
}
This small example elides such details as error handling, which a real protocol implementation would be likely to contain.
DESCRIPTION EVENTS
The following events are invoked, either using subclass methods or CODE references in parameters:
on_read_line $line
Invoked when a new complete line of input is received.
PARAMETERS
The following named parameters may be passed to "new" or "configure":
on_read_line => CODE
CODE reference for the "on_read_line" event.
METHODS
$lineprotocol->write_line( $text )
Writes a line of text to the transport stream. The text will have the end-of-line marker appended to it; $text should not end with it.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
perl v5.14.2 2012-10-24 IO::Async::Protocol::LineStream(3pm)