|
||||||
| Forums FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Programming/Scripting Questions about programming, bash scripts, perl, php, cron jobs, ruby, python, etc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Code:
cat MailingList | cut -d, -f1 | sort -u | wc -l name1 name2 2 I'd like the output from the sort to go to the terminal as well as to the pipe. I've used tee before, but I want all output to go to the terminal. I did some googling and scanned the bash doc at tldp which lend me down the path of trying a combination of parenthesis around the commands (subshell) and file descriptor redirecting. I haven't been successful. Any thoughts? Thank you. |
|
|||
|
Can't be done using bash redirections alone, you need a process to do the splitting.
Try: Code:
cut -d, -f1 < MailingList | sort -u | tee /dev/stdout | wc -l |
|
|||
|
Code:
cut -d, -f1 < MailingList | sort -u | tee >(wc -l) |
|
|||
|
So redirect the output of the tee to a subshell, that's one I totally missed. Argh. A subshell is definitely needed?
I was reading things that were swapping, or is that duplicating, file descriptors like: 3>&2 2>&1 1>&3. If tee didn't exist, is it possible? ![]() Using cat is a bad habit that keeps creeping. Redirection, pipes, file descriptors, subshells and their environment, is something I'm working on getting better at. Thanks all. |
|
|||
|
You could
Code:
cut -d, -f1 < MailingList | sort -u | tee /dev/stderr | wc -l And you can also Code:
exec 3>&1; cut -d, -f1 < pendientes | sort -u | tee /dev/fd/3 | wc -l; exec 3>&- Tee must be used yes or yes. The '|' redirects the stdout to the pipe, so stdout doesn't goes to the terminal anymore. If you want it to go to two different places you need two copies, that's what tee does. Your "3>&2 2>&1 1>&3" puts stdout in stderr and stderr in stdout. But since stderr is empty... |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|