?
Solved

Pull out line one from a text file?

Posted on 2000-05-10
5
Medium Priority
?
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

777 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