Write in a file with pipe also in same line

hi,
i want to write in a file the output of one command and pile also the same output

like ls -lrt > some_file | wc -l

ls -lrt > some_file | wc -l

The above won't work, storing to a file has to be done at the end, not before the pipe

ls -lrt  | wc -l > file

You can use something like below

ls -lrt  > file
cat file | wc -l

problem is that ls -lrt result is directed to the file that corect but wc -l is giving result zero
i want the number of line from the result ls -lrt
and write to a file at same time

ls -ltr > some_file ; wc -l < some_file >> some_file

:D:D:D

actually i m trying to create a command with pipe which can give the output 2 or 3 line ablove the result of the grep command
like
1
2
3
4
i grep 3 but i want the result 2 i.e one line above the required result
so i created the some thing like this
cat p | grep -n source_id | cut -d":" -f1 | xargs -i{} expr {} -1 | now_again_i_want_the_out_put_of_cat p | and again grep that particular line

what is your OS?

in grep do you have the option -B?

grep -B "3" file.txt

no this option is not in my OS grep
my os is AIX

use nawk or gawk

nawk '
($0 ~ s) {for (c=b+1;c>1;c--) print a[(NR+1-c)%b] ; print }
{a[NR%b]=$0;next }
' b=1 s='3' file.txt

b:- how many line to print before the pattern found.

:D:D:D

this is what tee is for...

ls -lrt | tee some_file | wc -l

awk '{a[NR]=$0}$0 ~ pattern{for(i=B+1;--i;){printf ((NR-i)? a[NR-i] ORS:x)}}' B=3 pattern=<pattern> infile

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.