Write result to output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Write result to output file
# 1  
Old 04-24-2012
Write result to output file

Good morning everybody,

Beeing an absolute newbie in shell scripting I would like to look for some help here.

I would like to read an external text file and format the data and write it to an output file.

What I was trying to do was to display the result (this worked).

But now I would like to write this result to a external file.

I would appreciate that some of you guys could help me out with this.

Here is what I did.

Code:
#!/usr/bin/perl
$data_file="theoriginalfile";
 
open(DAT, $data_file) || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);
## Start input to the output file
print "\$H:CREATE";
print "\n";
print "\$H:hardcodeevalue,hardcodeevalue,hardcodeevalue,hardcodeevalue";
print "\n";
foreach $lineintheoriginalfile (@raw_data)
{
chomp($lineintheoriginalfile );
($val1,$val2,$val3,$val4,$val5)=split(/\;/,$simline);
print "\$R:<PARENT>hardcodeevalue,${val1},,hardcodeevalue,,hardcodeevalue='':hardcodeevalue=${val2}:hardcodeevalue=${val3}:hardcodeevalue=${val4}:Profile=hardcodeevalue:A4KI=1:Model=hardcodeevalue:ADM=AA:Manufacturer=hardcodeevalue:OTA Key=1111 <CHILD>hardcodeevalue,${val5
},,L
OAD,,,";
print "\n";
}
print "\$F:";
#end input to the output file
print "\n";

the external file is similar to this
Code:
val1;val2;val3;val4;val5
val1;val2;val3;val4;val5
val1;val2;val3;val4;val5

I hope it's clear Smilie

Thank's a lot,

Moderator's Comments:
Mod Comment Welcome to the UNIX and Linux Forums. Please use [code] tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-24-2012 at 03:08 AM.. Reason: code tags
# 2  
Old 04-25-2012
You can run the script and redirect its output in any desired file as below.
suppose my script name is test.sh and i want to save its output in file called output.log then:
./test.sh >> output.log
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep output to file result not as expected

Hi Gurus, I run command grep ABC file1 > file2 against below file. I got all ABC_xxx in one line in file2. I expect to get multiple lines in file2. If I print result in screen, the result is expected. thanks in advance My os is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ABC_123 XXXXX... (2 Replies)
Discussion started by: green_k
2 Replies

2. Shell Programming and Scripting

Curl and write custom result to file

I have the following script, for i in $(cat MyWebApps); do curl -u manager:tH1s1s4f3k3p4ssw0Rd http://10.10.10.10:7529/manager/jmxproxy/"?get=Catalina:type=Manager,context=/$i,host=localhost&att=activeSessions"; done Which gives me an output like this OK - Attribute get... (12 Replies)
Discussion started by: charli1
12 Replies

3. Shell Programming and Scripting

Output block of lines in a file based on grep result

Hi I would appreciate your help with this. I have a output file from a command. It is broken based on initial of the users. Exmaple of iitials MN & SS. Under each section there is information pertaining to the user however each section can have different number of lines. MY challenge is to ... (5 Replies)
Discussion started by: mnassiri
5 Replies

4. Shell Programming and Scripting

Compare 2 file and write result

Hi friends...I have 2 files, file1.txt and reference.txt I could able to find difference using diff and following command awk 'NR == FNR { A=1; next } !A' reference.txt file1.txt above command listing data which is not in reference.txt 12.12 87 11.95 88 11.83 89 12.55 84... (12 Replies)
Discussion started by: Akshay Hegde
12 Replies

5. Shell Programming and Scripting

Script to write result to a file

Hello, How can I run this script every 1 hour and save its result to result.txt ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' Regards Shaan (5 Replies)
Discussion started by: Shaan_Shaan
5 Replies

6. Shell Programming and Scripting

How to output thre result to a text file?

Dear All I have a script file like the following: ..... ..... Variable_1 = 888 Variable_2 = 999 ..... MyExternalProgram Myfile ..... The line MyExternalProgram Myfile will generate some number, Say 777 Now I hope I can output the result of above codes to a text file,... (2 Replies)
Discussion started by: littlewenwen
2 Replies

7. UNIX for Advanced & Expert Users

Output the SQL Query result to a File

Hello Guys, This message is somewhat relates with last thread. But I need to re-write thing. I start over a little. I am stuck now and need your help. Here is my script- #! /bin/ksh export ORACLE_HOME=/opt/oracle/app/oracle/product/9.2 /opt/oracle/app/oracle/product/9.2/bin/sqlplus -s... (5 Replies)
Discussion started by: thepurple
5 Replies

8. Shell Programming and Scripting

Way to save output result of a program into another new file...

Does anybody know any alternative way to save output result of a program into another new file? I got try the command below: program_used input_file > new_output_file program_used input_file >> new_output_file Unfortunately, both the ">" and ">>" is not work at this case to save the output... (6 Replies)
Discussion started by: patrick87
6 Replies

9. Shell Programming and Scripting

Need to Output result to a non-delimitted file

Hello I need to run an sql script and then the output result to be in non-delimitted file What is the execution command to obtain this. For eg: the following outputs the result to a space delimitted file db2batch -d ${EC_DB2_DBNAME} -f ${TMP_SCRIPT_NAME} -a ${CURR_DB_ID}/${CURR_DB_PWD} -r... (1 Reply)
Discussion started by: cosec
1 Replies

10. Shell Programming and Scripting

any possible to run sql result and output to file

Hi, I search all post...and no soluation about..if i would like to run a sql statement and output the result to txt file. for example, i usually run "sql" to logon the database and run select statement. Then I need to copy the output into the result.txt. Can I run the script to do this... (7 Replies)
Discussion started by: happyv
7 Replies
Login or Register to Ask a Question