Regarding redirection using cat.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Regarding redirection using cat.
# 1  
Old 08-21-2008
Regarding redirection using cat.

The behavior of the following 2 operations is unexpected. K1 and K2 are files here :-

1) cat < K1 K2
The above operation should actually display contents of the both files.
But it gives the contents of K2 only. How is that ?

2) cat > K1 K2
Above operation takes the contents of K2 and writes it to K1 similar to
cat K2 > K1. How is that ?

Request anyone to please let me know.

Thanks a lot in advance.

Best Regards,
Marconi.
# 2  
Old 08-21-2008
Quote:
1) cat < K1 K2
The above operation should actually display contents of the both files.
I'm curious, what makes you think it should do that? My man page states
Quote:
Concatenate FILE(s), or standard input, to standard output.
(my emphasis), which I understand to mean "not both", i.e. if you give cat a file to read from, standard input is ignored.

Code:
cat > K1 K2

Like Latin, the word order is not as important as the syntax. >K1 means that the output goes into K1. You can achieve the same affect with
Code:
>K1 cat K2

# 3  
Old 08-21-2008
It's the expected behaviour: you need to pass to cat multiple filenames as arguments without the shell redirection (as far as I know only Z-Shell with the multios option set can handle multiple arguments with redirection).
The same for output redirection - you can do it with Z-Shell, otherwise you should use the tee command.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Difficulty with CAT redirection in script

I have not been able to append the contents of many files into one file. I have executed the CAT command shown below separately substituting an actual path and file name for the array variable to verify that I have the syntax correct. The bottom line - nothing is happening with CAT. I am running... (16 Replies)
Discussion started by: demmith
16 Replies

2. UNIX for Dummies Questions & Answers

about different redirection

explain the redirections 1>, 2>, 3>, ..... and 1< ,2<,3<..... where we use these things thanks Thread moved from AIX forum (2 Replies)
Discussion started by: tsurendra
2 Replies

3. Shell Programming and Scripting

Redirection

Hello All, I am using the below script to gather various tools running by the user, we have more than 100 tools running on the server so my challenge is to redirect memory & cpu load to the file with the name of the tool.so am using the below script i am stucking how to redirect to the file... (2 Replies)
Discussion started by: ajaincv
2 Replies

4. Shell Programming and Scripting

I/O redirection

Hello everyone,I'm reading a book and there's code fragment: exec 3>&1 ls -l 2>&1 >&3 3>&- | grep bad 3>&- exec 3>&- It says that the red part of that code does not close fd 3 but the green does close the fd 3.I can't understand that.....Why?Any predicate will be appreciated.:) (18 Replies)
Discussion started by: homeboy
18 Replies

5. UNIX for Dummies Questions & Answers

Help with Redirection

Hi Guys, I m new to UNIX and new to this forum. Was wondering if someone can help me understand redirection (standard input output pipeline etc) for starters, not too sure what this would mean who | sort > sortedfile | pr | lp im starting to understand common commands but when throwing... (2 Replies)
Discussion started by: jmack123
2 Replies

6. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

7. Shell Programming and Scripting

for i in `cat myname.txt` && for y in `cat yourname.txt`

cat myname.txt John Doe I John Doe II John Doe III ----------------------------------------------------------------------- for i in `cat myname.txt` do echo This is my name: $i >> thi.is.my.name.txt done ----------------------------------------------------------------------- cat... (1 Reply)
Discussion started by: danimad
1 Replies

8. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

9. UNIX for Dummies Questions & Answers

redirection to tty** with cat

I tried to cat a file to another user that was logged in, but I received an error message that displayed something like: %cat funny > /dev/ttyp3 zsh: permission denied: /dev/ttyp3 Thank you all for your help (1 Reply)
Discussion started by: zorro
1 Replies
Login or Register to Ask a Question