Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Confused over results using "tee" in piped command Post 302596892 by jazzmusic on Wednesday 8th of February 2012 01:54:16 PM
Old 02-08-2012
Confused over results using "tee" in piped command

First post here, so hopefully all guidelines are followed, and thanks in advance for any replies.

I'm working on a shell script(BASH) that processes a csv file and performs various tasks with the data. All is well, except I want to use 'tee' to send output from 'wc' to a file as well as pipe it to 'cut'. What I'm trying to accomplish is a) tally the record count from a list of files, and b) send the details of 'wc' to an output file.

This code successfully tallies the record count, but obviously isn't sending the output from 'wc' to an output file:

Code:
#!/bin/bash	
unset vCount verifyRecordCount
vCount=0
verifyRecordCount=0
   
outfile="./test2a.out"	
EXTRACT_FILES=`ls -d ./*`

for filename in ${EXTRACT_FILES}
do
   `wc -l $filename >> $outfile` 
   vCount=`wc -l $filename | cut -d" " -f1`
   echo "vCount="$vCount>>$outfile
   ((verifyRecordCount=verifyRecordCount+${vCount}))
done
echo "verifyRecordCount="$verifyRecordCount>>$outfile

I then insert a 'tee' into the mix and suddenly the setting of the vCount variable is 'broken'.

Here's the modified code:
Code:
#
# again, with feeling
#
unset vCount verifyRecordCount
vCount=0
verifyRecordCount=0
   
outfile="./test2b.out"
EXTRACT_FILES=`ls -d ./*`

for filename in ${EXTRACT_FILES}
do
   `wc -l $filename >> $outfile` 
   #vCount=`wc -l $filename | cut -d" " -f1`
   vCount=`wc -l $filename | tee >>$outfile | cut -d" " -f1`
   echo "vCount="$vCount>>$outfile
   ((verifyRecordCount=verifyRecordCount+${vCount}))
done
echo "verifyRecordCount="$verifyRecordCount>>$outfile
cat $outfile

I'd paste the results, but since this should run as is, suffice it to say that vCount is not getting set, and is blank.

What am I missing?

Thanks in advance.

Gary
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Results from "ls" command

Hello, I am uning IRIX64. I need to do an ls - 1 (one) command in order to get a one colum listing of the contents of a non current directory: t01:~ > ls -1 /scratch/u118807/reconstruct ./ ../ fr000202.rec fr000202.sin input_files/ input_files.tar sin000000.rec sin000000.sin... (8 Replies)
Discussion started by: scecilia
8 Replies

2. Shell Programming and Scripting

error "test: [-d: unary operator expected" very confused.

Im trying to check if a series of directory exists and if not create them, and am having issues. All the instances of test return with the error "test: #!/bin/bash location_Parent=~/Documents/sight_of_sound location_IMG=~/Documents/Sight_of_sound/IMG location_AUD=~/Documents/Sight_of_sound/AUD... (4 Replies)
Discussion started by: orionrush
4 Replies

3. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

4. Shell Programming and Scripting

Screen output is blocked by "| tee" command

BACK STORY: I have a script build.py . (It's for creating the ISO file for a special edition of Swift Linux.) This build.py script executes the mintConstructor.py script that I use to modify the Regular Swift Linux ISO to get the special edition Swift Linux ISO. The lines of the script that... (2 Replies)
Discussion started by: swiftlinux
2 Replies

5. Homework & Coursework Questions

C++ with Linux - writing a "tee"-like function

Greetings, everyone. 1. The problem statement, all variables and given/known data: I'm running into a problem with my program concerning the actual output it does. When I open the file that gets the output, it contains a large number of hex(?) variables and not what the user wants. The... (0 Replies)
Discussion started by: assignmentoper
0 Replies

6. Shell Programming and Scripting

The pipe not use "tee" to print on the screen for specific function

I have code fragment like { aa bb cc } > $LOG aa bb cc, all call function "ff", I want "ff" to print on the screen,but others do not print on the scree, is there a method? I can't use "tee", becasue tee I meet the write "error" ff() { echo "hello" } (2 Replies)
Discussion started by: yanglei_fage
2 Replies

7. Shell Programming and Scripting

Short command to create two files >{respo,nd}.php (with "tee" command?)

08:29 < xsi> >{respo,nd}.php bash: {respo,nd}.php: ambiguous redirect 08:31 < geirha> xsi: maybe you want tee So I was advised to do so. And I can't create two OR MORE files at once with {a,b,c,d,e,f}.php (which I quickly now need to create and to learn to create in the future to quickly... (2 Replies)
Discussion started by: Xcislav
2 Replies

8. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

9. UNIX for Beginners Questions & Answers

Append content using "tee" command

Hi, How to append content into a file using tee command echo " file1 is archived"| tee -a archive.txt echo " file2 is archived"| tee -a archive.txt echo " file3 is archived"| tee -a archive.txt how to append content as new rows in the archive.txt Thanks, Srinadh. (4 Replies)
Discussion started by: srinadhreddy27
4 Replies

10. Shell Programming and Scripting

Mindboggling difference between using "tee" and "/usr/bin/tee" in bash

I'm on Ubuntu 14.04 and I manually updated my coreutils so that "tee" is now on version 8.27 I was running a script using bash where there is some write to pipe error at some point causing the tee command to exit abruptly while the script continues to run. The newer version of tee seems to prevent... (2 Replies)
Discussion started by: stompadon
2 Replies
BF_TAR(1)						    Bogofilter Reference Manual 						 BF_TAR(1)

NAME
bf_tar - shell script to write a tar file of a bogofilter directory to stdout SYNOPSIS
bf_tar [-r] [-R] bogofilter_directory DESCRIPTION
bf_tar bundles a bogofilter working directory in tar format and copies it to standard output (your console, or where you redirect it, see EXAMPLES below). OPTIONS
The -r option causes bf_tar to remove inactive log files after the archive has been written successfully. The default is to leave log files. The -R option causes bf_tar to remove inactive log files before the archive is written. This may reduce chances that the resulting archive is recoverable should it become damaged. The archive may be smaller though. The default is to leave log files. EXIT STATUS
The script exits with status code 0 if everything went well, and nonzero if it encountered trouble. EXAMPLES
o bf_tar ~/.bogofilter > outfile.tar Writes a standard .tar file containing the essential files from ~/.bogofilter to outfile.tar. o bf_tar ~/.bogofilter | gzip -9 -c > outfile.tar.gz Writes a gzipped .tar.gz file containing the essential files from ~/.bogofilter to outfile.tar.gz. o bf_tar `pwd`/mydirectory > outfile.tar Prepend $(pwd)/ or `pwd`/ if you want to specify an absolute path instead of a relative path. NOTES
This script is meant for use with Berkeley DB based bogofilter versions. This script requires a SUSv2 compliant pax utility. This script expects a SUSv2 compliant shell. Solaris systems should have the SUNWxcu4 package installed (when bogofilter is configured) so that /usr/xpg4/bin/sh can be used. AUTHORS
Matthias Andree Bogofilter 10/22/2012 BF_TAR(1)
All times are GMT -4. The time now is 03:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy