Solved

Pull out line one from a text file?

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

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…

679 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