The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Java with Unix (Redirection + Piping) fluke_perf High Level Programming 3 04-30-2008 08:52 AM
sed redirection myle UNIX for Dummies Questions & Answers 3 03-12-2008 03:04 PM
Unix command redirection swap007 Filesystems, Disks and Memory 1 10-06-2007 04:52 AM
Unix redirection to '&-' DILEEP410 UNIX for Dummies Questions & Answers 6 08-31-2007 05:07 AM
redirection to tty** with cat zorro UNIX for Dummies Questions & Answers 1 11-02-2001 07:23 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-23-2007
Registered User
 

Join Date: Mar 2007
Posts: 23
redirection in unix, '<' as opposed to '>'

Greetings,

When directing in unix, symbol > means saving. E.g. I can save ls command output into mama like this:

ls -f > mama

Could someone give me a real example of how the opposite, i.e. symbol < is used?. Could not find its counterpart in Windows (I seem to learn better when i see unix's counterparts in windows upon which i depended for ages)

thanks
-a
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-23-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,454
more < some.txt
And that command works for me on Windows XP in a cmd window. On both XP and Unix I could have used:
more some.txt
but this is because the more command will process its arguments, find a filename, and open the file. Some commands, especially scripts that you may write may not have file opening code so they depend on being handed an opened file.
Reply With Quote
  #3 (permalink)  
Old 03-23-2007
Registered User
 

Join Date: Mar 2007
Posts: 23
perderabo, thanks a lot, you're a good man...

The way i was taught about script files is to first make them executable with: chmod +x filename; then execute them with: ./ filename.

Does your statement about script mean that the < symbol can be used instead of the chmod + x, ./ commands?.

Thanks a bunch,
-a
Reply With Quote
  #4 (permalink)  
Old 03-23-2007
cfajohnson's Avatar
Registered User
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 682
Quote:
Originally Posted by alikun
Greetings,

When directing in unix, symbol > means saving. E.g. I can save ls command output into mama like this:

ls -f > mama

Could someone give me a real example of how the opposite, i.e. symbol < is used?. Could not find its counterpart in Windows (I seem to learn better when i see unix's counterparts in windows upon which i depended for ages)

Code:
## Read first line from file:
read line < FILENAME
If the line contained leading or trailing spaces, they would be lost with that command. To prevent that, the internal field separator is cleared:
Code:
IFS="" read line < FILENAME
If there are any backslashes in the line, they will be removed and the literal character following will be used. If the last character on the line is a backslash, read will continue reading the next line.

To disable backslash escaping, use the -r option:
Code:
IFS="" read -r line < FILENAME
To read an entire file (if the file is long, sed or awk may be a better tool to use):
Code:
while IFS="" read -r line
do
    ## Do something with the line here
done < FILENAME
The input of other commands can also be redirected from a file. For example, to change all uppercase As to Zs:
Code:
tr A Z < FILENAME
Reply With Quote
  #5 (permalink)  
Old 03-24-2007
Registered User
 

Join Date: Mar 2007
Posts: 23
cfajohnson, thanks a lot for detailed explanation; i got the idea...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0