Hi, I know that you can use the head -1 command in unix to print the first line of a file. I have a data file and I need to read in the file, print the header of the input file to an output file, then do a number of other things aside from this. What command or function can I use to print the header line to an output file. You probably do not need to see my code but it is included for your reference. I don't want to change my code, rather just figure out a simple way to print the header of my input file to an output file. Thanks.
#!/usr/bin/perl #use strict; use warnings; #print "Enter the input file name: "; #my $filename = <STDIN>; #chomp ($filename); @ARGV == 1 or die "Invalid number of arguments. Please supply as argum +ents: \n1) the input file listing all data to be used."; my ($input_file) = @ARGV; open (IN, "$input_file") or die "Cannot open file: $!"; #head -1 <IN>; #my $firstline = IN; my $x=0; my @keys; my @holder; my @array_hash; my $threshold=.03; my $blank = "-"; my $nonsyn = "nonsynonymous"; open (OUTFILE, ">TEST_$input_file") or die "Cannot create an output fi +le: $!"; while(my $line = <IN>) { print OUTFILE head -1; chomp($line); $x++; if ($x==1) { (@keys)=split(/\t/, $line); } else { my $y=0; (@holder) = split(/\t/, $line); my %hash; for my $column (@holder) { $hash{$keys[$y]}=$column; $y++; } # -ne print OUTFILE; exit; # my $first = shift (@array_hash); # print OUTFILE $first; if ($hash{"1000_Genomes"} ne $blank) { if ($hash{"1000_Genomes"} <= $threshold) { if ($hash{"Syn/Nonsyn"} eq $nonsyn) { print OUTFILE $line, "\n"; } } } if ($hash{"1000_Genomes"} eq $blank) { # if ($hash{"1000_Genomes"} <= $threshold) # { if ($hash{"Syn/Nonsyn"} eq $nonsyn) { print OUTFILE $line, "\n"; } # } } } }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |