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 :

Line1 ..Line 2Line3 Line4 Line 5

Expected:

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.

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

Hi,
Below is the script.I have declared variable for check.log .I am using echo to set for the document

echo "-------------File Check------------------" > check.kog

-This is not working in script but working in terminal.

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.

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 .

  echo "-------------Backup Check-------------" > check.log
               >> more check.log
   -------------Backup Check-------------
 

echo is working in terminal

Thanks,
karthik

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.

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.

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 find command.

Thanks,
R. Singh

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.

The main reason for the undesired behaviour posted in #1 is the missing quotes around $content when echo ing it to the results file. But, on top of the syntactical errors alluded to by Don Cragun, and e.g. the misunderstanding on what is a file and what is a variable, there might be a logical problem: the order of result lines produced by find can't be predicted as they are the result of an optimization process, so your tail -20 might give different results every time it is run...