Redirect to a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Redirect to a file
# 1  
Old 05-06-2014
Redirect to a file

Hi,


Is there a way to redirect the output of a set of commands to a file instead of using << at every command in bash shell. For eg

Code:
(echo hostname 
echo "Comparing 2 files"
comm -3 file1 file2) >>file3


Last edited by Don Cragun; 05-07-2014 at 12:08 AM.. Reason: Change HTML tags to CODE tags.
# 2  
Old 05-06-2014
Only if you place them in a script.
This User Gave Thanks to Aia For This Post:
# 3  
Old 05-06-2014
You can group them with { ... ; } or ( ... ) or you can use exec.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 4  
Old 05-06-2014
Yes
Code:
exec >> /tmp/output.log 2>&1

Put this line at the beginning of the script and all the following commands will redirect their output to the mentioned file
This User Gave Thanks to SriniShoo For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read file from input and redirect to output file

Hi , i am having an file which contains 5 file_name data, i need to read the file name and will perform certain operation and generate out file names with named as 5 individual file_names for eg: file.txt contains file_name1.txt|hai file_name2.txt|bye file_name3.txt|how... (3 Replies)
Discussion started by: rohit_shinez
3 Replies

2. Shell Programming and Scripting

Redirect Variable Value to a File

I have shell script generate.sh that has var="HP-UX" I am following example 19-8 in the below document. Here Documents The output.txt is generated however I want the value of variable var to be reflected in the contents of the output.txt file cat <<'EOF' #!/bin/bash connect("Welcome... (1 Reply)
Discussion started by: mohtashims
1 Replies

3. Shell Programming and Scripting

ksh- redirect stderr to file and then modify the file

I have the following: remsh $host -n 2>>syslog_issue_list.txt grep -i -e "EMS" -e "error" -e "warning" -e "excessive" /var/adm/syslog/syslog.log | awk /"$DATE1"/ | awk -vhost="$host" '!/remsh|telnetd/{print host "\n", $0 >> "syslog_issue_list.txt"}' I am creating a health script that has... (4 Replies)
Discussion started by: chipblah84
4 Replies

4. Shell Programming and Scripting

Redirect lines to another file

Hi, I have a file with a size of 10 mb and I need to redirect some specific lines to a new files. For eg. Executed Restore for 11227.EDCS.551.01.201110 from /tmp/bk/restore/CR81500/content/S24U15VA2.2010-10-29.16:49.EDT/ArchiveFile_11227.EDCS.551.01.201110.zip Operation output: <U+FEFF>Oct... (4 Replies)
Discussion started by: gsiva
4 Replies

5. Shell Programming and Scripting

TOP redirect to file

Okay, this is what I have and what I need. top -p 11111 >> test.txt Unfortunately, when I do that in a script, when I run my next command, could be just an 'ls -l' it says that the process stops and it doesn't write to the test.txt file anymore. I guess the first part isn't as big of a... (5 Replies)
Discussion started by: cbo0485
5 Replies

6. Shell Programming and Scripting

compare and redirect to new file

hi i have two file a.txt 123,b,c,d,e 111,c,d,e,f, 456,a,k,j,h b.txt 123 678 987 321 456 i want to compare these two files(match content of b first coloum with a ) and o/p should be like 123,d,e 456,j,h pls help.....:) (7 Replies)
Discussion started by: anish19
7 Replies

7. HP-UX

how to redirect the growing contents of log file to another file in unix

how to redirect the growing contents of log file to another file in unix (2 Replies)
Discussion started by: megh
2 Replies

8. UNIX for Dummies Questions & Answers

redirect output to a file name

Hi all!! is possible to assign the output of some command to filename, i.e. grep_output.txt Otherwise, I want to open a new file which name is inside another, how can I do it? Thanks a lot! (7 Replies)
Discussion started by: csecnarf
7 Replies

9. HP-UX

How to Redirect the error messages from Syslog file to our own Application Log File

Hello, I am New to Unix. I am Using HP-UX 9000 Series for my Application. I am Currently Facing an Issue that the error messages are being written in the syslog file instead of the Application Log File. The Codes for that Syslog.h is written in Pro*C. I want to know how to Redirect these... (3 Replies)
Discussion started by: balasubramaniam
3 Replies

10. UNIX for Dummies Questions & Answers

Redirect output to a file

Ahhhrrrggg I'm having a brain fart... I want to take the output of a command and redirect it to a file... This works.... $ man cp | cat >> copy_help but this doesn't keytool -help |cat >> keytool_help It just produces... these lines... more keytool_help ] ... ... (11 Replies)
Discussion started by: jimmyc
11 Replies
Login or Register to Ask a Question