Sponsored Content
Top Forums Shell Programming and Scripting Perl: combine Backtick & system() I/O operation? Post 302425827 by durden_tyler on Sunday 30th of May 2010 03:07:48 PM
Old 05-30-2010
No, that second argument is either a filename or an array of filenames to which the output of command ("dir") would be redirected.

Code:
$ # print the output of "dir" on the screen
$ # and also redirect the output of "dir" to the file "file1.out"
$ perl -le 'use Tee; tee("dir", "file1.out")'
testfile  testfile.out
$ 
$ # check the content of the file "file1.out" now
$ cat file1.out
testfile  testfile.out
$ 
$ # the same as what was printed on the screen

Same thing with an array of filenames:

Code:
$ 
$ # print the output of "dir" on the screen
$ # and also redirect the output of "dir" to the files in the array
$ # "@files" i.e. file2.out, file3.out and file4.out
$ perl -le 'use Tee; @files = qw (file2.out file3.out file4.out); tee("dir", @files)'
file1.out  testfile  testfile.out
$ 
$ # now check the contents of file2.out, file3.out and file4.out
$ cat file2.out
file1.out  testfile  testfile.out
$ 
$ cat file3.out
file1.out  testfile  testfile.out
$ 
$ cat file4.out
file1.out  testfile  testfile.out
$ 
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Multi operation system in one pc.

Does anyone can write a thread to teach me how to install Windows 2000, RH Linux, and FreeBSD unix in one machine step by step? Or someone's already done with this topic? (1 Reply)
Discussion started by: HOUSCOUS
1 Replies

2. Ubuntu

where can i get the unix operation system?

I am a stranger here ,where can i get the operation for free.thank you! (2 Replies)
Discussion started by: tcb3210
2 Replies

3. UNIX for Dummies Questions & Answers

what does the operation '>&' mean in a shell script

hi, all, i saw a syntax like this usr/local/mpiexec -np 8 /home/XXXX/program_exe >& ./temp/out the output will be put into ./temp/out. I want to know the meaning of the operation symbol '>&'. Thanks (3 Replies)
Discussion started by: cy163
3 Replies

4. Shell Programming and Scripting

combine two perl lines into a single perl command

Hi Everyone, i have a string 00:44:40 so: $tmp=~ s/://gi; $tmp=~s/({2})({2})({2})/$1*3600+$2*60+$3/e; the output is 2680. Any way to combine this two lines into a single line? Thanks (4 Replies)
Discussion started by: jimmy_y
4 Replies

5. Shell Programming and Scripting

Perl: Backtick Errors

When trying to use backticks for system commands, is there a way to read the error messages if a command doesn't execute properly? I have no problem getting the results if the command is properly executed. Ex. my @result = `dir`; foreach my $line (@result) { print "Result = $line";... (2 Replies)
Discussion started by: kooshi
2 Replies

6. Linux

commands of linux operation system

Am actually am new to the linux operating system and knda wana knw more about it.Please could u help me with some commands so i can start with that first.Really need your help (5 Replies)
Discussion started by: GODBLESSME
5 Replies

7. UNIX for Dummies Questions & Answers

system calls and atomic operation

Are system calls atomic operations? Is a system call can be interrupted? (2 Replies)
Discussion started by: vistastar
2 Replies

8. Shell Programming and Scripting

Enter third column & Perform Operation

I am trying to enter a third column in this file, but the third column should that I call "Math" perform a some math calculations based on the value found in column #2. Here is the input file: Here is the desired output: Output GERk0203078$ Levir Math Cotete_1... (5 Replies)
Discussion started by: Ernst
5 Replies

9. AIX

Monitoring AIX with System Center Operation Manager 2007 R2

I can get my AIX servers to show up in SCOM but I'm struggling with running personal scripts and have the result of these scripts show up in SCOM. I'm currently using BigBrother and I've written some scripts for BB. I would like to convert these scripts to something that can be used in SCOM. ... (0 Replies)
Discussion started by: petervg
0 Replies

10. Shell Programming and Scripting

Help me to perform count & group by operation in shell scripting?

Hi All, I want to display the distinct values in the file and for each distinct value how may occurance or there. Test data: test1.dat 20121105 20121105 20121105 20121105 20121106 20121106 20121106 20121105 I need to display the output like Output (2 Replies)
Discussion started by: bbc17484
2 Replies
CAT(1)							    BSD General Commands Manual 						    CAT(1)

NAME
cat -- concatenate and print files SYNOPSIS
cat [-benstuv] [file ...] DESCRIPTION
The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-line order. If file is a single dash ('-') or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it and then reads it until EOF. This complements the UNIX domain binding capability available in inetd(8). The options are as follows: -b Number the non-blank output lines, starting at 1. -e Display non-printing characters (see the -v option), and display a dollar sign ('$') at the end of each line. -n Number the output lines, starting at 1. -s Squeeze multiple adjacent empty lines, causing the output to be single spaced. -t Display non-printing characters (see the -v option), and display tab characters as '^I'. -u The -u option guarantees that the output is unbuffered. -v Display non-printing characters so they are visible. Control characters print as '^X' for control-X; the delete character (octal 0177) prints as '^?'. Non-ASCII characters (with the high bit set) are printed as 'M-' (for meta) followed by the character for the low 7 bits. DIAGNOSTICS
The cat utility exits 0 on success, and >0 if an error occurs. EXAMPLES
The command: cat file1 will print the contents of file1 to the standard output. The command: cat file1 file2 > file3 will sequentially print the contents of file1 and file2 to the file file3, truncating file3 if it already exists. See the manual page for your shell (i.e., sh(1)) for more information on redirection. The command: cat file1 - file2 - file3 will print the contents of file1, print data it receives from the standard input until it receives an EOF ('^D') character, print the con- tents of file2, read and output contents of the standard input again, then finally output the contents of file3. Note that if the standard input referred to a file, the second dash on the command-line would have no effect, since the entire contents of the file would have already been read and printed by cat when it encountered the first '-' operand. SEE ALSO
head(1), more(1), pr(1), sh(1), tail(1), vis(1), zcat(1), setbuf(3) Rob Pike, "UNIX Style, or cat -v Considered Harmful", USENIX Summer Conference Proceedings, 1983. STANDARDS
The cat utility is compliant with the IEEE Std 1003.2-1992 (``POSIX.2'') specification. The flags [-benstv] are extensions to the specification. HISTORY
A cat utility appeared in Version 1 AT&T UNIX. Dennis Ritchie designed and wrote the first man page. It appears to have been cat(1). BUGS
Because of the shell language mechanism used to perform output redirection, the command ``cat file1 file2 > file1'' will cause the original data in file1 to be destroyed! BSD
September 15, 2001 BSD
All times are GMT -4. The time now is 04:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy