Redirecting output to file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Redirecting output to file
# 1  
Old 09-27-2016
Redirecting output to file

Hi,

I have created script which redirect the output to file.I am able to get the output in file but not in the format.

Output :Content of the log which have 10 -15 lines.

Actal :
Code:
Line1 ..Line 2Line3 Line4 Line 5

Expected:
Code:
Line1
                Line 2
                Line3

Please suggest how to make this.

Thanks,
Karthhik

Last edited by Scrutinizer; 09-27-2016 at 12:29 AM.. Reason: code tags
# 2  
Old 09-27-2016
Quote:
Originally Posted by karthik771
Hi,
I have created script which redirect the output to file.I am able to get the output in file but not in the format.
Output :Content of the log which have 10 -15 lines.
Actal :
Code:
Line1 ..Line 2Line3 Line4 Line 5

Expected:
Code:
Line1
                Line 2
                Line3

Please suggest how to make this.
Thanks,
Karthhik
Hello Karthik771,

Please use code tags as per forum rules for your codes/commands/Input_file which you are using into your posts. Your Input_file doesn't look in correct format may be you haven't pasted it correctly, if I am not wrong here you require space in between strings to be changed into new line. If this is the case then following may help you in same.
Code:
tr ' ' '\n' < Input_file

Also if above is not meeting your requirements then please use CODE TAGS and show us your correct sample for Input_file and expected output with all your conditions, I hope this helps you.

Thanks,
R. Singh
# 3  
Old 09-27-2016
Below is the content

Hi,
Below is the script.I have declared variable for check.log .I am using echo to set for the document
Code:
echo "-------------File Check------------------" > check.kog

-This is not working in script but working in terminal.
Code:
BackupFile=$(find </path/>*.fnr -type f -mtime -1 -print )
content=$(tail -20 "$BackupFile")
echo $content > check.log

Thanks,
Karthik

Last edited by Don Cragun; 09-27-2016 at 02:25 AM.. Reason: Add CODE and ICODE tags.
# 4  
Old 09-27-2016
Quote:
Originally Posted by karthik771
Hi,
Below is the script.I have declared variable for check.log .I am using echo to set for the document
Code:
echo "-------------File Check------------------" > check.kog

-This is not working in script but working in terminal.
Code:
BackupFile=$(find </path/>*.fnr -type f -mtime -1 -print )
content=$(tail -20 "$BackupFile")
echo $content > check.log

Thanks,
Karthik
What shell are you using?

What operating system are you using?

Exactly how are you invoking your shell script? Did you get any error messages when you invoked your shell script? (If so, exactly what diagnostics were produced?)

There are some syntax errors in your script that makes me very surprised that it works when you type it into a terminal session. Since you are redirecting the output from find into a file (assuming there is only one) with the filename extension .fnr, the variable BackupFile will be an empty string.
# 5  
Old 09-27-2016
Hi

I am using -csh shell.

Operating system is Red Hat Enterprise Linux Server release 6.6

I am not getting any error while executing the script.

Filename with *.fnr will be generating daily.I am finding the file with today date .
Code:
  echo "-------------Backup Check-------------" > check.log
               >> more check.log
   -------------Backup Check-------------

echo is working in terminal

Thanks,
karthik
# 6  
Old 09-27-2016
Hello karthik771,

Could you please try it in a single command, if you are not using your other variables and let us know how it goes then.
Code:
find complete_path_to_your_files*.format_of_your_files -type f -mtime -1 | tail -20 > check.log

If you want all those variables then you could try following on same too.
Code:
BackupFile="$(find -type f -mtime -1 -printf '\n%P')"
content=$(echo "$BackupFile" | tail -20)
echo "$content" > check.log

I am considering here you need last 20 records(files) which we will get from findcommand.

Thanks,
R. Singh
# 7  
Old 09-27-2016
Quote:
Originally Posted by Don Cragun
What shell are you using?

What operating system are you using?

Exactly how are you invoking your shell script? Did you get any error messages when you invoked your shell script? (If so, exactly what diagnostics were produced?)

There are some syntax errors in your script that makes me very surprised that it works when you type it into a terminal session. Since you are redirecting the output from find into a file (assuming there is only one) with the filename extension .fnr, the variable BackupFile will be an empty string.
I asked what command you used to invoke your script and you have not yet answered that question. Except for the echo commands, none of the commands you have shown us are valid when using csh as your shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help with redirecting output to an HTML file

1. The problem statement, all variables and given/known data: I'm having trouble redirecting the output of my sysinfo_page script into my sysinfo_page.html file. The task at hand is to be able to email both the html file and the script to myself. I'm assuming that the html should appear as a web... (8 Replies)
Discussion started by: braing
8 Replies

2. Shell Programming and Scripting

Redirecting output to file through cron

Hi Does anyone have any suggestions for capturing the output into a file when i run it through cron? I have file called "quick.1" which contains two simple commands to be executed on the target host. And i have second file called "quick.2" which contains the wrapper script to ssh to the target... (1 Reply)
Discussion started by: chandika_diran
1 Replies

3. UNIX for Dummies Questions & Answers

redirecting the script output to more than 1 file

Hi, I want to redirect my script output to more than one file without printing the result to the screen. How to do that? ex: echo "hi" >> a.txt b.txt cat a.txt hi b.txt :confused: (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

4. Shell Programming and Scripting

Redirecting output to file

Hi, Below is the whole string which is to be redirected to the new file. su - oracle -c "exp $user/$pass file=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.dmp log=/oracle/oradata/backup/exp_trn_tables_`date +%d_%b_20%y_%H_%M_%S`.log tables=table1,table2 statistics=none" ... (3 Replies)
Discussion started by: milink
3 Replies

5. Shell Programming and Scripting

Redirecting output of Make to file

Hi, I am unable to get this script to work as desired. Basically, if an argument "log" is sent into the script, it outputs the result of the Make to a file output.log. However, if the argument is not passed, I want the output to be just put on screen (no redirection). See code snippet below. #... (3 Replies)
Discussion started by: srujan45
3 Replies

6. Shell Programming and Scripting

Redirecting output to both console and to a file

Hi All, Is there a way in Bash we can redirection some output to both console and the file at the same time. ~Parag (2 Replies)
Discussion started by: paragkalra
2 Replies

7. Shell Programming and Scripting

Redirecting output of a command to a file

Hi We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from... (3 Replies)
Discussion started by: ankitgoel
3 Replies

8. Shell Programming and Scripting

Redirecting <talk> output to a file

Is it possible to run <talk> such that both sides of the conversation are written to the screen and also to a file? I use the utility to chat with collaborators and sometimes it would be nice to have a record of our conversation while we are problem solving. I am running OS X, so <talk>... (4 Replies)
Discussion started by: cej
4 Replies

9. Shell Programming and Scripting

Redirecting my output to a specific file

Hi guys am doing some checking inside my script and i want to redirect my output to a specific file for example checking if a move was successfully done and was writing on the screen whether the move was successful or not and now want to write same thing into a file... I am new to shell... (2 Replies)
Discussion started by: Lutchumaya
2 Replies

10. UNIX for Dummies Questions & Answers

Redirecting output file to a different server.

Hi, I hope this is problem makes sense and that someone can offer some advice. Basically i have a perl script which accesses a database and outputs the information to a file. Is it possible to use a 'system' command to embeb some Unix command which moves that file to another directory... (3 Replies)
Discussion started by: Stormrider
3 Replies
Login or Register to Ask a Question