Solved

Pull out line one from a text file?

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now