Extracting column value from perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting column value from perl
# 1  
Old 08-31-2011
Extracting column value from perl

Hello

Kindly help me to find out the first column from first line of a flat file in perl

I/P

Code:
 
9869912|20110830|00000000000013009|130|09|10/15/2010 12:36:22|W860944|N|00
9869912|20110830|00000000000013013|130|13|10/15/2010 12:36:22|W860944|N|00
9869912|20110830|00000000000029207|292|07|05/29/2001 10:35:32|DADS_JAMESA|N|00


O/P
Code:
 
9869912

The file is pipe (|) delimeted


Thanks a lot!!
# 2  
Old 08-31-2011
Code:
perl -e '
my $a = (split /\|/, scalar <>)[0]; 
print "$a\n"
' INPUTFILE

This User Gave Thanks to yazu For This Post:
# 3  
Old 08-31-2011
--delete--
# 4  
Old 08-31-2011
THANKS a lot Yazu

Can you please kindly let me know how to include the same in perl script

when I use the below code in perl script

Code:
 
$a = (split /\|/, scalar <>)[0] $file;

I am having the below error

Code:
 
Scalar found where operator expected at Balancing.pl line 101, near "] $file"
        (Missing operator before  $file?)
syntax error at Balancing.pl line 101, near "] $file"
Execution of Balancing.pl aborted due to compilation errors.

Thanks again
# 5  
Old 08-31-2011
Code:
open my $fd, "<", $file;
my $a = (split /\|/, scalar <$fd>)[0];
close $fd;

Hmm... Why do you need a perl solution if you know nothing about perl? Smilie
This User Gave Thanks to yazu For This Post:
# 6  
Old 08-31-2011
Thanks again

Yes rite now I know almost nothing in perl but I was asked to do it in perl only .The same I did in unix but I had to do it in perl.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

FORTRAN program to extracting column

Dear folks I have a large data set which contains 400K columns. I decide to select 50K determined columns from the whole 400K columns. Is there any suggested fortran program which could do this process for me? I need to also mention that I store all of the columns id in one file which may help... (1 Reply)
Discussion started by: sajmar
1 Replies

2. Shell Programming and Scripting

Extracting the column containing URL from a text file

I have the file like this: Timestamp URL Text 1331635241000 http://example.com Peoples footage at www.test.com,http://example4.com 1331635231000 http://example1.net crack the nuts http://example6.com 1331635280000 http://example2.net ... (0 Replies)
Discussion started by: csim_mohan
0 Replies

3. Shell Programming and Scripting

Parsing a column and extracting subsets

Please help with this.. my file sizes exceed 40GB,,not possible to do manually. I have a string in the 2nd column that has strings like 5M108N31M, 3S2M100N45M4S etc..the first column is a number. There can be 0,1 or 2 number of S but only 1,2 Ms and only 1 N. S only occurs at the... (4 Replies)
Discussion started by: ritakadm
4 Replies

4. Shell Programming and Scripting

Help with File processing - Extracting the column

I have a line from table space report: 5 135_TT ms Normal 1774336.0 1774208.0 761152.0 1013056.0 57.1% Now I have to get 1013056.0 as o/p. For this I tried cut -f32 -d" " previously it worked now it is showing empty space. Suggest me the best code for this which... (1 Reply)
Discussion started by: karumudi7
1 Replies

5. Shell Programming and Scripting

Extracting rows with a certain column

Hi, I want to extract rows that have specific characters at a certain column. It might be best to show you my problem. So my tab delimited file looks like this: YPR161C 10 16 864445 866418 - Verified 3.558 YOL138C 6 15 61325 65350 - Verified 0.6... (1 Reply)
Discussion started by: phil_heath
1 Replies

6. UNIX for Dummies Questions & Answers

Extracting the last column of a text file

I would like to extract the last column of a text file but different rows of the text file have different numbers of columns. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

extracting a column using search term

I am trying to select a column using a search term. My input file looks like this (tab delimited): ABC BJS FDG GHH DGH DFG GHF 95 456 5 266 87 4567 67 3 54 678 4567 45 6 36 232 55 3 5 6 8 34 cat filename | awk '{print $2}'above code will give me the second column. However, what I want... (2 Replies)
Discussion started by: SangLad
2 Replies

8. UNIX for Advanced & Expert Users

extracting/copy a column into a new column

Hello, Anybody out there knows how to copy a column data into a blank column using unix command? Thanks (1 Reply)
Discussion started by: folashandy
1 Replies

9. Shell Programming and Scripting

Extracting a column using AWK

Hi, I've a text file like ABC,,100 A,100,200 In the above example, I have 3 columns. I want to extract the second column. I'm expecting a value like 100 i.e first record will not have any value but still it has to give me null value. second record should give 100. Can anybody... (2 Replies)
Discussion started by: ronald_brayan
2 Replies

10. Shell Programming and Scripting

Extracting one column from a ps -ef command

Hi, I want to extract one value/column from a ps -ef command. Here's an example of the output: mqm 14552 1 0 15:48:43 - 0:00 amqpcsea SWNETTQ1 mqm 57082 1 0 15:48:42 - 0:00 amqpcsea SWNETDQ1 mqm 88104 1 0 15:26:37 - 0:00 amqpcsea SWNETEQ1... (6 Replies)
Discussion started by: m223464
6 Replies
Login or Register to Ask a Question