Its PERL + Comma separated seventh field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Its PERL + Comma separated seventh field
# 8  
Old 06-02-2009
Quote:
Originally Posted by sweetblood
What does your script look like?
I agree with this question.

ganapati, what code have you written or tried so far? It is best for you to try to write some code and show folks what you have attempted.

-----Post Update-----

Quote:
Originally Posted by fpmurphy
Ganapati, you will get much more help from people on this forum if you post what you
have come up with so far. People are more than willing to help but it can be diffcult to
see exactly where you need help without seeing what you have attempted so far.

A simple Web search will show you plenty of examples of how to do what you want to do.

Meanwhile, here is a pointer to Parsing CSV using Perl
Agreed. Thanks fpmurphy.
# 9  
Old 06-03-2009
Dear friends,

As I told you earlier, I'm totally new to PERL. I know shell scripting very well, but now the requirement is PERL!!

I've to alter existing perl code and the only changes is to read the "Semicolon" separated file (sorry, not comma separated as mentioned earlier) and store the seventh field to an array for later comparison.

The problem I'm facing is, I don't know how to extract only the seventh field in perl. I know its very easy using AWK. But now the change is in existing perl script.

Hence requested for your kind help.

Thanks.
# 10  
Old 06-03-2009
Quote:
Originally Posted by ganapati
Dear friends,
As I told you earlier, I'm totally new to PERL. I know shell scripting very well, but now the requirement is PERL!!
when you are new to something, you read up the docs, type this: perldoc perl
then try looking at this: perldoc -f split
# 11  
Old 06-08-2009
Error

I found the answer, struggling at the begining, you all suggested me.
Thanks for all.

my @arr_print = split( /;/, $line );
print "$arr_print[7]\n" ;


With Regards / Mysore Ganapati.

"There are no secrets to success. It is the result of preparation, hard work, and
learning from failure." - Colin Powell
# 12  
Old 06-08-2009
If you only want the 8th field (7th index) from a list use a slice:

Code:
my $token7 = (split( /;/, $line))[7]; 
print "$token7\n" ;

# 13  
Old 06-22-2009
Error array scope outside the loop

Hi,

I've another problem with the scope of array. I'm not able to print array elements (for 8th field) outside the loop. But I can print this within the loop.

open( my $in, '<', $inputfilename )
or croak "Cannot open file '$inputfilename': $!";

my @orig_array;
while ( my $line = <$in> ) {
chomp $line;
@orig_array = split( /;/, $line );
print "$orig_array[7]\n" ; ## I can print elements here.
}
print "$orig_array[7]\n" ; ## I can't print elements here.


Please suggest me.

Last edited by ganapati; 06-23-2009 at 07:07 AM.. Reason: to correct a small mistake.
# 14  
Old 06-23-2009
Hi Ganapati.

I think that problem due to scope of the array and its elements. Try that.
May be some experts can help you!!

All the best.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract fields from a CSV i.e comma separated where some of the fields having comma as value?

can anyone help me!!!! How to I parse the CSV file file name : abc.csv (csv file) The above file containing data like abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)
Discussion started by: J.Jena
4 Replies

2. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

3. Shell Programming and Scripting

Need comma separated output

Hi, I am having the file with server names & its corresponding process, i need your help how to convert into comma separated output between server & app #cat apps.txt Server1 oracle was Server2 http webadmin Server3 tsm db2 My requirement is like below. Server1,oracle/was... (5 Replies)
Discussion started by: ksgnathan
5 Replies

4. Shell Programming and Scripting

Comma separated to rows based on field

Hi to all, I have a file like: chr1 a1 a2 a3 a4 a5 a6,a7,a8,a9 chr1 b1 b2 b3 b4 b5 b6,b7 chr2 c1 c2 c3 c4 c5 c6,c7,c8,c9,c10 ... I would like an output like this: chr1 a6 chr1 a7 chr1 a8 chr1 a9 chr1 b6 chr1 b7 chr2 c6 chr2 c7 chr2 c8 (6 Replies)
Discussion started by: aec
6 Replies

5. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

6. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

7. Shell Programming and Scripting

Inserting string in between field in comma separated file

Hello Mates, I have one txt file having commo seperated values. I have to insert string "FALSE" in 2nd field from the end. E.G SE18 6RN,,,,5439070,1786840,,1000002148671600,123434 Out put should be: SE18 6RN,,,,5439070,1786840,FALSE,1000002148671600,123434 Can some one help me to... (8 Replies)
Discussion started by: krsnadasa
8 Replies

8. Shell Programming and Scripting

Perl script to parse output and print it comma separated

I need to arrange output of SQL query into a comma separated format and I'm struggling with processing the output... The output is something like this: <Attribute1 name><x amount of white spaces><Atribute value> <Attribute2 name><x amount of white spaces><Atribute value> <Attribute3... (2 Replies)
Discussion started by: Juha
2 Replies

9. Shell Programming and Scripting

How to format file into comma separated field

Guys, Need you help, i have a a file content that look like this. Nokia 3330 <spaces><spaces><more spaces>+76451883874 Nokia 3610 +87467361615 so on and so forth, - there are so many spaces in between. - e.g.... (5 Replies)
Discussion started by: shtobias
5 Replies
Login or Register to Ask a Question