Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Command output redirection to file issues

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 1 Week Ago
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 23 June 2017, 11:03 AM EDT
Location: Lancashire, UK
Posts: 3,141
Thanks: 1,316
Thanked 600 Times in 542 Posts
You could also replace code like this:-
Code:
for file in *
do
   if [ "$file" = "File_A" ]
   then
      echo "Found A" >> logfile.txt
   fi
   if [ "$file" = "File_B" ]
   then
      echo "Found B" >> logfile.txt
   fi
   if [ "$file" = "File_C" ]
   then
      echo "Found C" >> logfile.txt
   fi
done

.... with something like this:-

Code:
for file in *
do
   if [ "$file" = "File_A" ]
   then
      echo "Found A"
   fi
   if [ "$file" = "File_B" ]
   then
      echo "Found B"
   fi
   if [ "$file" = "File_C" ]
   then
      echo "Found C"
   fi
done > logfile.txt 2> logfiles.err

It's terrible dummy code, I know, but it has one output redirection and all STDOUT from the loop goes to it.

Does that give you something to work with to smarten your code?



Robin
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command output redirection in script not working haritha.gorijav Shell Programming and Scripting 7 05-22-2012 01:10 AM
output redirection command knowledgeSeeker UNIX and Linux Applications 2 02-04-2012 01:49 PM
Help with tar --append command output redirection pganguly46 Shell Programming and Scripting 0 02-01-2011 04:32 AM
awk output redirection to file learnscript Shell Programming and Scripting 6 03-03-2010 08:35 PM
Output file redirection aagajaba UNIX for Dummies Questions & Answers 1 04-25-2009 12:24 AM



All times are GMT -4. The time now is 09:53 AM.