need help on how to read command in unix


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers need help on how to read command in unix
# 1  
Old 05-19-2008
Question need help on how to read command in unix

can any one please help me how to use "read" command for openig a file.i want to process the file record by record and then needs to search for a particular string at a particular position.can any one please let me know the code.i am new to the shell.

below are sample sample records

D6303200805066HJ8164-61002EURO6303I0073554514
D6303200805066HJ8164-61002EURO6303I0073554514

your help would appreciate.....


thanks
rao.
# 2  
Old 05-19-2008
read simply reads standard input. You probably want to use redirection.

Code:
while read line; do
  echo "Read line '$line'"
done <file

Without concrete information about which particular string at which particular position, it's hard to do anything useful inside that loop, but it should hopefully be enough to get you started.
# 3  
Old 05-19-2008
Error need help on how to read command in unix

thanks ray.
i have seen the below code.but i am not getting wht the "line" signifies in the read command?i am very new to unix scripting.could you please write elabrately somethign in the code.
coming to search pattern i have to search at 14and15 postion of the record whether it equals to '6h' or not.if so i have to write that coressponding record into a separate file.

i really appreciate your help.

advancedthanks
narasimharao.
# 4  
Old 05-19-2008
If that's all you need, read is not really appropriate.

Code:
egrep '^.{13,14}6h' file >separatefile

(Or 6H if that's what you really mean; grep and friends are case sensitive by default. Add the -i option to ignore case distinctions.)

read variablename reads a line of input, which is subsequently available in $variablename -- you can of course call your variables anything you like.

("ray", huh? Had't come across that particular one before ...)

Last edited by era; 05-19-2008 at 09:21 AM.. Reason: egrep -i to ignore case
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need help with read command

Is there a way to make the input of the read command (or some similar command that I'm unaware of) not visible, or with an astrix?? An example: #!/bin/bash # Example echo; echo "Who are you??"; read name if ; then echo "Welcome, the terminal is yours."; exit else "Stranger... (2 Replies)
Discussion started by: Huitzilopochtli
2 Replies

2. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

3. Shell Programming and Scripting

Help with UNIX READ command usage..

Tested on : bash Will be implementing on : ksh I dont know if this is weird , or my idea of Unix stdin or stdout is completely messed up , but if I use the following command, I am getting a proper output. ls -l | head -1 | while read a ; do echo $a ;done and the output is soemthing like... (5 Replies)
Discussion started by: kumarjt
5 Replies

4. UNIX for Dummies Questions & Answers

Read all files in a directory for a unix command

Hello, Below, I have a unix command, which can be executable for single file. cat input.txt | sort -k3,3 > output.txt I have 100 input files in a directory. It is hectic and time taking to run the above command for all the 100 files for 100 times. Now, I want to execute the above unix... (2 Replies)
Discussion started by: koneru_18
2 Replies

5. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

6. UNIX for Dummies Questions & Answers

Read command

Hi everyone, I have problem while writing a shell script for linux (Red Hat). First I need to create a read command. I tried to google this but so far I can't sort this out. I hope you will be able to help me. I have to read a file like this : GESTION_DATA_SET_variable1_variable2 ... (2 Replies)
Discussion started by: Aswex
2 Replies

7. Shell Programming and Scripting

read command

'Morning vmstat 1 1|sed 1,2d|awk '{printf("%s\n",$1)}'|read var echo $var This syntax run on AIX (ksh) but not on linux (bash). I think that problem is the read command, because the following syntax is ok : vmstat 1 1|sed 1,2d|awk '{printf("%s\n",$1)}' Could someone help me! regards... (16 Replies)
Discussion started by: nymus7
16 Replies

8. Shell Programming and Scripting

AWK : read unix command

Hi, Is there a way to have something working like the read Unix command to stop a awk ask a question and get the result. I've try system("read a") but it does not work. Thanks. Franck. (6 Replies)
Discussion started by: fwirbel
6 Replies

9. UNIX for Dummies Questions & Answers

Read Command

i need to create a script that inputs information from another file using the read command. Sounds easy enough but i can't figure it out, can anyone help me? (2 Replies)
Discussion started by: Woodbird25
2 Replies

10. UNIX for Dummies Questions & Answers

while using read command I want too.....

This is the greatest site ever, only my second day of use and the responses and advice I got from yesterdays question were great.. Now for todays question, I have a file that I want to read one line at a time into a script i've written. Once I have read the line I would like to update it (in... (1 Reply)
Discussion started by: nhatch
1 Replies
Login or Register to Ask a Question