?
Solved

Pull out line one from a text file?

Posted on 2000-05-10
5
Medium Priority
?
242 Views
Last Modified: 2010-03-05
Hi.......
I would like to grab the first line in a csv file so I can process it as column headings for updating/inserting rows in a Sybase db with the data that follows in the rest of the csv.
Any help pointers appreciated
regards
0
Comment
Question by:rickyr
5 Comments
 
LVL 8

Expert Comment

by:shlomoy
ID: 2796799
$cvs_filename = "change_this_with_a_full_path_to_the_file";
open(IN,"<$cvs_filename") || die "can't open : $!\n";
$line = <IN>;
close(IN) || "can't close $cvs_filename: $!\n";


print "the first line of $cvs_filename is $line\n";

0
 
LVL 12

Expert Comment

by:geotiger
ID: 2797052
If you are opt to other options, here are two:

awk '{IF (NR == 1) print $0}' your_file

head -n1 your_file

0
 
LVL 16

Accepted Solution

by:
maneshr earned 200 total points
ID: 2797271
you might want to try this...

$cvs_filename = "change_this_with_a_full_path_to_the_file";

open(IN,"$cvs_filename") || die "can't open : $!\n";

## Read all the lines in an array.
@lines= <IN>;
close(IN) || "can't close $cvs_filename: $!\n";

print "The column header is ....\n\n $lines[0]\n";

print "The column values are...\n";
foreach (1..$#lines){
  print $lines[$_],"\n";
}
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2822239
any luck with this??

did you find the solution you were looking for??

let us know.
0
 
LVL 3

Author Comment

by:rickyr
ID: 2822570
ta
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question