Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Cat Input & Output to a Log file


 
Thread Tools Search this Thread
# 1  
Cat Input & Output to a Log file

Team,

we use below command to store the contents in a logfile.

Code:
cat a.txt > a.log

a.txt content is

Code:
123
345

Is there any options available to store the command used also?

for eg a.log may show as

Code:
cat a.txt
123
345

# 2  
You can do it like this:
Code:
echo cat a.txt > a.log
cat a.txt >> a.log

# 4  
Hello,

Here is one more approach.

Code:
echo "cat a.txt" | cat - a.txt >> brnew.txt

Output will be for file as follows.

Code:
$ cat brnew.txt
cat a.txt
abc    def
def    xyz
123   5678


Thanks,
R. Singh
# 5  
When needing to see the command because troubleshooting a script you may want to use
Code:
set -x

in your script.
The following commands may also be of interest :
Code:
man tee

Code:
man exec

If you want to log your session into a file (what you type and what you get), also have a look at
Code:
man script

Little example below :
Code:
# script my.log
Le script a commencé, le fichier est my.log
# cat a.txt
123
345
# exit
Script terminé, le fichier est my.log
# cat my.log
Début du script sur mer 18 déc 2013 15:30:57 CET
# cat a.txt
123
345
# exit

Script terminé sur mer 18 déc 2013 15:31:07 CET
#

In blue the content of the my.log file
# 6  
Try this (but you won't see what you type);
Code:
exec 5>&1 6>&2 >&a.log
cat a.txt
exec  1>&5 2>&6

This saves stdout and stderr to some dummy file descriptors, redirects them to x.log, and later restores them from the dummies.
 

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Getting output from a file similar to cat output
anil510
I have a file # cat /root/llll 11 22 33 44 When I cat this file content to a variable inside a shell script and echo that shell script, it does not show up as separate lines. I need echo output similar to cat. cat /root/shell_script.sh #!/bin/bash var=`cat /root/llll` echo $var... Shell Programming and Scripting
2
Shell Programming and Scripting
Unable to copy file using SCP (Input/output & Permission denied error)
Technext
Hi, I am facing issue while using scp. Source & target machines are Linux & HP-UX respectively. On target machine, if I fire the following command, I get error: Now if I try scp on another file, which is on the same source machine, it works fine. All directories and subdirectories...... UNIX for Dummies Questions & Answers
2
UNIX for Dummies Questions & Answers
Dynamic output file generation using a input text file with predefined output format
hudson03051nh
Hi, I have two files , one file with data file with attributes that need to be sent to another file to generate a predefined format. Example: File.txt AP|{SSHA}VEEg42CNCghUnGhCVg== APVG3|{SSHA}XK|"password" AP3|{SSHA}XK|"This is test" .... etc --------- test.sh has...... Shell Programming and Scripting
1
Shell Programming and Scripting
how to input the CAT command output in Shell
troubleurheart
Hi guys... I am new to this scripting...so please forgive me if anything worng in my questions... here is my question.. I have file structure /home/oracle/<sid>/logs/bkup now i want to write a script which should grep the sid name from a file..and it should replace the <SID> with...... Shell Programming and Scripting
1
Shell Programming and Scripting
for i in `cat myname.txt` && for y in `cat yourname.txt`
danimad
cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat...... Shell Programming and Scripting
1
Shell Programming and Scripting

Featured Tech Videos