Solved

Pull out line one from a text file?

Posted on 2000-05-10
5
226 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 50 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl script to parse log and delete the file 17 182
Perl strange behaviour 5 75
Need help with bash and/or perl commands on OS X Terminal 9 113
Replace  text in a file 2 128
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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 …
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…

742 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