redirecting to stdout in betwen command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting redirecting to stdout in betwen command
# 1  
Old 03-15-2010
redirecting to stdout in betwen command

can anyone help me in making singleline command for

Capital Letters are folders ,small letter are files


X,Y,Z are subfolders of A

as shown below

A - X,Y,Z


Folder X has three files a.txt,b.txt,c.txt similarly Y,Z.
as shown below

X- a.txt,b.txt,c.txt
Y- a.txt,b.txt,c.txt
Z- a.txt,b.txt,c.txt



Now i want the count no.of files in all subfolders in A

comp:A admin$ ls | xargs wc -l

will give the count in each folder

but what i want is to print X and its count also

X
3
Y
3
Z
3

Now what i want is to print "X" on screen before its piping to xargs

MAINIDEA: The main idea of this question is it possible to redierct output to screen before piping to another command

eg: i tried just like

comp:A admin$ ls | xargs tee |xargs wc -l
comp:A admin$ ls | tee |xargs wc -l

but not working any ideas???
# 2  
Old 03-15-2010
count no.of files in all subfolders in A

Code:
find /A -type f |wc -l

# 3  
Old 03-15-2010
Quote:
Originally Posted by rdcwayx
count no.of files in all subfolders in A

Code:
find /A -type f |wc -l

MAINIDEA: The main idea of this question is it possible to redierct output to screen before piping to another command
# 4  
Old 03-16-2010
Code:
use strict;
use warnings;
use Data::Dumper;
my $var1=shift;
my $var;
    if( -d $var1)
    {
opendir(DIR,$var1);
my @array=readdir(DIR);
foreach(@array)
{
    $var=$var1."/".$_;
    if($var eq "." || $var eq "..")
    {
        next;
    }
    if( -d $var)
    {

        opendir(DIR1,"$var") or die "Can't Open: $!\n";
        my @array1=readdir(DIR1);
        my $count=$#array1-1;
        print $_ .":".$count."\n" unless $_ eq ".." || $_ eq ".";
    }
}

}
    else
    {
        print "else\n";
        exit
    }

# 5  
Old 03-16-2010
Code:
ls | tee >(wc -l)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Redirecting stdout inside a loop

hi, OK. I am writing a bash script, and it is almost working for me. Problem 1: I currently have stout sent to a file (stout.miRNA.bash.$date_formatted) which I would like to have work inside my loop, but when I move it, it just prints to the screen. Problem 2: I have a second file... (18 Replies)
Discussion started by: hmortens
18 Replies

2. Shell Programming and Scripting

Redirecting stdion, stdout within an AT command

Hello, I'm strugling with some redirecting and all help is apreciated. The following program is working as expected, but the result of the AT command doesn't go to any file. Thanks in advance for the help. #!/bin/bash modem=/dev/ttyUSB1 file=/root/imsi.txt # print error to stderr and exit... (4 Replies)
Discussion started by: cleitao
4 Replies

3. Shell Programming and Scripting

Redirecting stdout problem

I have a simple bash script that prints sth every 5 seconds. What I do is the following. I redirect the output of the script to a file, tail the file and see that it works and then from another console I delete the file where the output is redirected to. Even though I have deleted the file, the... (2 Replies)
Discussion started by: igurov
2 Replies

4. Shell Programming and Scripting

Redirecting stdout on background task

Hello, I have a script (videostream.sh) which invokes the GStreamer command-line tool gst-launch with all the correct command line parameters. When I invoke this program, I add the '&' character at the end to make it a background task, so that my script can complete and exit, i.e. gst-launch... (1 Reply)
Discussion started by: salukibob
1 Replies

5. Shell Programming and Scripting

Redirecting stdout to variable while printing it

Hi everybody, I am trying to do the thing you see in the title, and I can't simply do a=$(svn up) echo $a because the program (svn) gives output on lots of lines and in the variable the output is stored on only one line (resulting in a horribly formatted text). Any tips? Thanks,... (2 Replies)
Discussion started by: ocirne94
2 Replies

6. Shell Programming and Scripting

Redirecting stdin/stdout to/from command from/to string

Hi, I am working on a project where I have to generate and execute nasm code on-the-fly. I generate the code in a file program.asm and then execute it.This output is to stdout which i redirect to an output file which i read back to compare results: system("nasm -f elf program.asm >... (5 Replies)
Discussion started by: doc_cypher
5 Replies

7. UNIX for Dummies Questions & Answers

Redirecting several outputs to /dev/stdout

I have an executable that, depending on its input, outputs to either one file or several. It usually prints nothing on screen. The usual way to call this program is to specify an input and output filenames, like this: ./executable.exe -i inputfile -o outputfileIt will then try to use the output... (1 Reply)
Discussion started by: aplaydoc
1 Replies

8. Shell Programming and Scripting

Redirecting part of output to stdout

Hi, I am trying to execute a command like this: find ./ -name "*.gz" -exec sh -c 'zcat {} | awk -f parse.awk' \; >> output If I want to print the filename, i generally use the -print argument to the find command but when I am redirecting the output to a file, how can I print just the... (2 Replies)
Discussion started by: Legend986
2 Replies

9. Shell Programming and Scripting

implicitly redirecting stdout to a file

Is there a way to redirect all stdout to a file implicitly - like defining stdout=/home/me/process.log - so that all "echo" commands in several scripts/subscripts are written to that file; instead of having to edit all scripts to redirect the "echo" (e.g. echo 'This is a test ' >>... (1 Reply)
Discussion started by: ALTRUNVRSOFLN
1 Replies

10. Shell Programming and Scripting

redirecting STDOUT & STDERR

In bash, I need to send the STDOUT and STDERR from a command to one file, and then just STDERR to another file. Doing one or the other using redirects is easy, but trying to do both at once is a bit tricky. Anyone have any ideas? (9 Replies)
Discussion started by: jshinaman
9 Replies
Login or Register to Ask a Question