split question perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting split question perl
# 1  
Old 09-01-2005
split question perl

I am interested in 2 and 36th fields in this input file. I was wondering if there was a more efficeint way to do this.

($pt1,$bkup_name,$pt3,$pt4,$pt5,$pt6,$pt7,$pt8,$pt9,
$pt10,$pt11,$pt12,$pt13,$pt14,$pt15,$pt16,$pt17,
$pt18,$pt19,$pt20,$pt21,$pt22,$pt23,$pt24,$pt25,
$pt26,$pt27,$pt28,$pt29,$pt30,$pt31,$pt32,$pt33,
$pt34,$pt35,$tcpname,$pt37)=split(/,/,$tmpArr[$x]);
# 2  
Old 09-01-2005
Code:
awk -F"," { print $2,$36 }' filename

# 3  
Old 09-01-2005
Same efficiency, just a twist in the way you get the params:

Code:
@fieldAry = split(/,/,$tmpArr[$x]);
@wantedFieldAry = @fieldAry[1..35];

# 4  
Old 09-02-2005
Sorry. Thought you wanted another way, outside perl.
# 5  
Old 09-03-2005
Thanks guys.
Jim I was looking for a perl solution.
# 6  
Old 07-20-2006
Just thought I'd revisit this cause I discovered that you can get to a specific field by using a splice. If I want the 2nd and 36th field you can do

($field2,$field36) = (split /,/, $tmpArr[$x]) [2,36];

Hope this is helpful to others.
# 7  
Old 07-20-2006
Quote:
Originally Posted by reggiej
($field2,$field36) = (split /,/, $tmpArr[$x]) [2,36];
Hmm. Then you are extracting the 3rd and the 37-th in this case. Are you (assuming you have a default value of $[ )?

By the way, I think I made an error in my earlier post. I meant to use [1,35] instead of [1..35]. Didn't see until you bring up this today.

Last edited by cbkihong; 07-20-2006 at 10:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split the string in perl

Hi All, How to split the string KAR_Celltick_Ban_GSMGW3 and want to pickup the third filed. Sometime the string may be "KAR_Celltick_Ban" like this Thanks in advance (1 Reply)
Discussion started by: sujit_kashyap
1 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Perl Question - split function with csv file

Hi all, I have a csv file that appears as follows: ,2013/03/26,2012/12/26,4,1,"2017/09/26,5.75%","2017/09/26,1,2018/09/26,1,2019/09/26,1,2020/09/26,1,2021/09/26,1",,,2012/12/26,now when i use the split function like this: my @f = split/,/; the split function will split the data that is... (2 Replies)
Discussion started by: WongSifu
2 Replies

3. Shell Programming and Scripting

Perl split and join

Hi, I have tried the split and join functions but stuck with unexpected results. Any help appreciated. I pass multiple values at command line like perl test.pl -type java,xml. This works good for me but i am not sure how to print it in the required format. Here is the code i tried:... (4 Replies)
Discussion started by: nmattam
4 Replies

4. Programming

Perl Split Issue

Hello All - I am having trouble with the split command in perl. Here is what I am trying to do. 75|2455345|2455349|00:00:00|00:00:00|Once|0|Frank Vacation | | 5 I want to only print out the 8th column. So that would be "Frank Vacation" and "Power Down" I need to run this on a file that... (16 Replies)
Discussion started by: tarken
16 Replies

5. UNIX for Dummies Questions & Answers

File split question

I have a flat file in UNIX and I have to perform two tasks based on the below data. The data I have printed here is just sample the original data is too long. The position 110 to 111 (two digit value I have bolded the values) theygives the record type detail in the sample above the record types... (7 Replies)
Discussion started by: techsavvy007
7 Replies

6. Shell Programming and Scripting

Perl split question

hi, I have a seemingly really stupid question, but here goes! What do you enter into split delimiter to seperate something like this "December 12, 1995" and get December 12 1995 ? thanks (5 Replies)
Discussion started by: ade214
5 Replies

7. Shell Programming and Scripting

Use split function in perl

Hello, if i have file like this: 010000890306932455804 05306977653873 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC30693599000 30971360000 ZZZZZZZZZZZZZZZZZZZZ202011302942311 010000890306946317387 05306977313623 0520080417010520ISMS SMT ZZZZZZZZZZZZZOC306942190000 30971360000... (5 Replies)
Discussion started by: chriss_58
5 Replies

8. UNIX for Advanced & Expert Users

Split Command in Perl

Hi, I have to split a line of the form 1232423#asdf#124324#54534#dcfg#wert#rrftt#4567 into an array in perl. I am using @fields; @fields=split('#',$line); if($fields eq "1") But this is not working. By using the syntax, the statements in "if" are never executed. Please help.... (9 Replies)
Discussion started by: rochitsharma
9 Replies

9. Shell Programming and Scripting

split to array in perl

Collegues I have flat file in the following format. 137 (NNP Kerala) (NNP India) 92 (NN Rent) (NN Range) 70 (NNP Thiruvananthapuram) (NNP Kerala) 43 (NNP Tourist) (NNP Home) 40 (NNP Reserve) (NNP Now) 25 (SYM @) (NN hotelskerala) 25 (NNP Thiruvananthapuram-695001) (NNP Kerala) 23 (NN... (3 Replies)
Discussion started by: jaganadh
3 Replies

10. UNIX for Dummies Questions & Answers

Split and recombine question

Hi guys I would like to be able to split a large file into many smaller part. Then, these smaller files will be transfered onto a windows machine where they need to be recombined. I think tar files may be the best to do this. How can I tar a large file into many small tar files which can be... (1 Reply)
Discussion started by: white_raven0
1 Replies
Login or Register to Ask a Question