redirection in unix, '<' as opposed to '>'


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers redirection in unix, '<' as opposed to '>'
# 1  
Old 03-23-2007
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
# 2  
Old 03-23-2007
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.
# 3  
Old 03-24-2007
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
# 4  
Old 03-24-2007
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

# 5  
Old 03-24-2007
cfajohnson, thanks a lot for detailed explanation; i got the idea...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

Rescue "LiveCD" for UNIX (as opposed to Linux)

Background is I am attempting to recover/rescue an HP DL380 G5 which is running SCO Unixware 7.11. It has 3 partitions in a RAID 5 Configuration and is unable to boot with a Stage 3 boot load error. .. Client has no emergency rescue disk. System is old and redundant except they suddenly need some... (4 Replies)
Discussion started by: BernP
4 Replies

2. UNIX for Dummies Questions & Answers

redirection in unix

how to redirect a output value to a file (1 Reply)
Discussion started by: pratima.kumari
1 Replies

3. Shell Programming and Scripting

Effect of using eval to execute a command as opposed to writing it on the commandline

cmd='date | wc' or cmd="date | wc" $cmdIf this script is executed, an error is generated. The reason written was that "The execution fails because the pipe is not expanded and is passed to date as an argument". What is meant by expansion of pipe. When we execute date | wc on the command line, it... (2 Replies)
Discussion started by: daudiam
2 Replies

4. Shell Programming and Scripting

Help with Output Redirection of a Unix Shell Script

Hi Guys, I have a script for which the stdout and stderr should be redirected to a log file, they should not be printed on the screen. Could you please let me know the procedure to redirect the output of the script to a log file. Thanks in advance. --- Aditya (5 Replies)
Discussion started by: chaditya
5 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

Unix shell output redirection help

Hi all, Actually i need to know whether there is any way to redirect the output of shell operations into any file without pipe . Actually my problem is , i run some command & its result is displayed on shell after some calculations on shell, so if i redirect its output to file, it is not... (5 Replies)
Discussion started by: sarbjit
5 Replies

7. Programming

Java with Unix (Redirection + Piping)

Hi, To explain this question I will have to go into a bit of detail. I hope you don't mind. currently I have a log handler (an already compiled c++ version) and what it does is makes a log file and writes all the unix output (echo, etc) of a script to that log file. To me the log_handler is... (3 Replies)
Discussion started by: fluke_perf
3 Replies

8. Shell Programming and Scripting

redirection

Hi, The code below works, it's a part of a bash shell script that serve to search a pattern $pattern_da_cercare in the files contained in a directory $directory_iniziale. Now the proble is: How can I redirect stderr to a file? PS: so I want to redirect ALL the errors to a file. I tryed... (9 Replies)
Discussion started by: DNAx86
9 Replies

9. Filesystems, Disks and Memory

Unix command redirection

Hi all,, Is there any way to redirect the command o/p directaly to a memory location instead of redirecting it to the file?? (1 Reply)
Discussion started by: swap007
1 Replies

10. UNIX for Dummies Questions & Answers

Unix redirection to '&-'

Hi UF family members, I am intermediate in Unix language and scripting.I know the redirection systems in unix,but the below statement confuses me: #!/bin/ksh . $HOME/.profile 2>&- Actually this is an extract from a unix script which was trying to set the... (6 Replies)
Discussion started by: DILEEP410
6 Replies
Login or Register to Ask a Question