The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Split Command in Perl rochitsharma UNIX for Advanced & Expert Users 9 03-09-2008 03:56 AM
split to array in perl jaganadh Shell Programming and Scripting 3 07-06-2007 06:29 AM
Perl Split Command usage maheshsri Shell Programming and Scripting 2 12-17-2006 08:30 AM
multiple pattern split in perl umen Shell Programming and Scripting 3 08-01-2006 03:43 AM
perl split function new2ss Shell Programming and Scripting 5 06-08-2006 11:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-01-2005
reggiej reggiej is offline
Registered User
  
 

Join Date: May 2005
Posts: 27
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 (permalink)  
Old 09-01-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805

Code:
awk -F"," { print $2,$36 }' filename

  #3 (permalink)  
Old 09-01-2005
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
Same efficiency, just a twist in the way you get the params:


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

  #4 (permalink)  
Old 09-02-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805
Sorry. Thought you wanted another way, outside perl.
  #5 (permalink)  
Old 09-03-2005
reggiej reggiej is offline
Registered User
  
 

Join Date: May 2005
Posts: 27
Thanks guys.
Jim I was looking for a perl solution.
  #6 (permalink)  
Old 07-20-2006
reggiej reggiej is offline
Registered User
  
 

Join Date: May 2005
Posts: 27
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:08 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0