using 'more' instead of 'cat' to pipe into another command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers using 'more' instead of 'cat' to pipe into another command
# 1  
Old 07-01-2010
using 'more' instead of 'cat' to pipe into another command

Hi, quick question. Since i am in the habit of using 'more' to view files, e.g.

Code:
$ more my_file.txt

I often use this command to pipe into other utilities like grep. For example,

Code:
$ more my_file.txt | grep '^>'

would get all lines in the file that begin with ">". I know that it is generally recommended to use 'cat' for this purpose, so I was wondering if there is a speed difference between the two commands? In other words, would it be faster to say:

Code:
$ cat my_file.txt | grep '^>'

? Since i routinely work with very large text files, the speed difference could be important.



(Note: I realize that 'grep' takes a file argument like this:
Code:
$ grep '^>' my_file.txt

but i am only using it as an example. It can be anything. I am more interested in the 'cat' vs. 'more' difference.)

Thanks!

Last edited by pludi; 07-01-2010 at 10:48 PM.. Reason: code tags, please...
# 2  
Old 07-01-2010
There is a format difference between "more" and "cat". The "more" process includes screen formatting characters. Don't ever feed the output from "more" into a pipe for further processing, use "cat" or shell inward redirect.
# 3  
Old 07-01-2010
If it has a single file as argument, more behaves exactly like cat. If it has more, headers will be added.
# 4  
Old 07-02-2010
i believe more is of more for a user, and not for feeding it as input to other process...

in any command line, you will almost see more only as the very last command.
# 5  
Old 07-02-2010
Yes, that's what I meant. "more" is only meaningful when its output is the user's tty. When it is piped to a process, all the internal interaction logic is disabled.

Last edited by jlliagre; 07-02-2010 at 05:33 PM..
# 6  
Old 07-02-2010
more

also... when in "more", you can press "v" and the content will be loaded into "vi", it is very convenient, I learned it from unixacademy.com "Learn Linux For A Beginner" training
# 7  
Old 07-02-2010
This is the kind of interaction logic that is disabled in the OP case.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cat a script, pipe it, then pass arguments to it?

suppose i have a perl script that is normally run this way: ./checkdisk.pl -H hostname -w 40 -c 80 but, for whatever reason, i cannot run the script directly as it should. But i can cat it through pipe. How can i pass the arguments "-H hostname -w 40 -c 80"? so this is what i'm doing,... (6 Replies)
Discussion started by: SkySmart
6 Replies

2. Shell Programming and Scripting

Help need on cat command

I have two files as below 1.txt AA 123 CC 145 DD 567 2.txt AA 111 YY 128 CC 144 FF 222 DD 777 ZZ 875 basically 1.txt is updated file, if i do cat 1.txt 2.txt output should be as below o/p (2 Replies)
Discussion started by: Tecnical_help12
2 Replies

3. AIX

cat command

Hi. How can i write a command on AIX like the one i did at linux that find string in a file and show me that string, and return 3 lines before and 4 lines after that string. my linux command is: /bin/cat <filename> | tail -150 | grep -B2 -A8 "<string to look for>" Example: /bin/cat ... (10 Replies)
Discussion started by: yechi_r
10 Replies

4. Homework & Coursework Questions

Need some help on using cat command

I have a file "sample.txt" with the content as below: Hi This is a Sample Text. I need a single command using cat which serve the following purpose. 1.display the contents of sample.txt 2.append some text to it 3. and then exit But, all should be served by a sinle... (1 Reply)
Discussion started by: ashok.g
1 Replies

5. 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

6. UNIX for Advanced & Expert Users

cat command

Dear All I have two text files File1.txt and File2.txt . I am concatenating the two files and making it as single file Cat_File.txt. Now i need to keep joined file in two different path. that is I need to use cat command only once ,but store joined file in two different locations. Since... (3 Replies)
Discussion started by: tkbharani
3 Replies

7. 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

8. AIX

cat command

I would like to append some statement into 1 single file so that it can be concatenate together in 1 word. I have tried >> but it will seperate my 2 statement into 2 rows. # cat abc.txt cde.txt > result.txt where abc.txt is "abcde" and cde.txt is "12345" the result should come out as... (3 Replies)
Discussion started by: kwliew999
3 Replies

9. Shell Programming and Scripting

cat command

What does the below command means $cat <<% >abc.txt (3 Replies)
Discussion started by: surjyap
3 Replies

10. Shell Programming and Scripting

the CAT command

hi everybody, how do i open a txt file writen in unix on to a web page so when i want to view the txt file that was generated from a shell program, that file is open on a web page do i use the cat > filename.html command to do this, or is there another way many thanks :D (2 Replies)
Discussion started by: alexd
2 Replies
Login or Register to Ask a Question