Print @array content to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print @array content to a file
# 1  
Old 03-21-2012
Print @array content to a file

Hi, as the title, I have an array @f_lines with gene information in it. How can I put the content of @f_lines into a file so that I can read it?

I tried this:
Code:
open(OUTPUT, "file"); # put gene information in this file;
@f_lines = ("gene1", "gene2", "gene3"...); # gene information;
print OUTPUT @f_lines;
close(OUTPUT);

I didn't get any warnings, neither did i see gene information in "file".

Does anyone know the problem? Thanks very much for help~

By the way above is part of the script I ran in a shell.

Last edited by Franklin52; 03-21-2012 at 06:54 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 03-21-2012
Code:
open(OUTPUT, ">file");

Guru.
# 3  
Old 03-21-2012
Quote:
Originally Posted by guruprasadpr
Code:
open(OUTPUT, ">file");

Guru.
Yes I did put ">" in. Sorry I forgot to post that.
# 4  
Old 03-21-2012
Hi.

This code:
Code:
#!/usr/bin/env perl

# @(#) p1	Demonstrate write to file.

use warnings;
use strict;

my (@f_lines);

open( OUTPUT, ">file" );    # put gene information in this file;
@f_lines = ( "gene1", "gene2", "gene3" );    # gene information;
print OUTPUT @f_lines;
close(OUTPUT);

produces:
Code:
leap 1224 $ ./p1
leap 1224 $ cat file
gene1gene2gene3leap 1224 $

For this context:
Code:
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
perl 5.10.0

You may have missed the line if you didn't include a newline.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare & print content of file which is not matching

Hi All I want to compare 2 files using awk and get output of content which is not matching I have 2 files a.txt 123 456 780 143 b.txt A|B|C|167|D|E C|K|D|123|D|E A|B|D|789|G|F C|D|G|143|A|B Not matching line from b.txt O/P A|B|C|167|D|E A|B|D|789|G|F (3 Replies)
Discussion started by: aaysa123
3 Replies

2. Shell Programming and Scripting

Ksh: how compare content of a file with an other array

Hi, I created a skript in ksh which generate a file with semicolon as separator, this is an example of the file a created: example content file: hello;AAAA;2014-08-17 hello;BBBB;2014-08-17 hello;CCCC;2014-08-17 I would need to compare the content in of the second column of this file... (3 Replies)
Discussion started by: jmartin
3 Replies

3. Shell Programming and Scripting

Not getting array in .awk file and print it

I have test.sh file as below : set -A IDARR $ID echo | awk -f test.awk -v TempArr="${IDARR }" I have test.awk file as below : BEGIN { Flag = 1; } { print "Hello"; for(i in TempArr) { print i; } } (9 Replies)
Discussion started by: nes
9 Replies

4. Shell Programming and Scripting

Script to process file from a directory and grep the required content and print

Hi All, below script reads the perticular files from the directory. Am trying to fetch status and print them in the required format. It needs to read line and search for string "Passed/Failed" and print them under correct sub header. script : BASE_DIR=/tmp/test/REPORT/CollectReport #... (16 Replies)
Discussion started by: Optimus81
16 Replies

5. Shell Programming and Scripting

Print array into a single file - AWK

Hi all, I been looking for a solution to the fact that when I use: for (i=1; i<=NF; i++) print $ifields that are originally in a single line are printed in a single line I have severals files for which the first 7 are the same, but the number of variables after that can vary, for example NF... (5 Replies)
Discussion started by: PaulaL
5 Replies

6. Shell Programming and Scripting

want to print the file content from the specific line

Hi All, I would like to print the content from the specific line of a file . For example... i have file abc.txt which has 100 lines of code ,from this file i would like to print the content from 20,19,18th line......like that Regards Srikanth (4 Replies)
Discussion started by: srikanthg
4 Replies

7. Shell Programming and Scripting

Read a text file and print the content..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... ... (7 Replies)
Discussion started by: samupnl
7 Replies

8. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

9. Shell Programming and Scripting

file content in an array PERL

Hello everybody, I'm new in this forum. I searched a long time for a solution for my problem but I didn't find the right thing. I have to read from a file (content is "abngjm" without any other signs) and have to write this content in an array. But every sign has to be called by its own... (5 Replies)
Discussion started by: e_prof
5 Replies

10. UNIX for Dummies Questions & Answers

Print the content of a directory in jpg file

Is there any possible way to print the contents of a directory to a .jpg file? I have a list of thumbnails (e-books) which I want to share (+500) but I don't know how to make this. I would appreciate a lot any comments regarding this issue. (4 Replies)
Discussion started by: agasamapetilon
4 Replies
Login or Register to Ask a Question