how do we retrieve a line from a file in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how do we retrieve a line from a file in unix
# 1  
Old 02-07-2007
traversing line by line in a file

we need to capture a record from a file in to a variable and do modifications to it .. so capturing line by line in a file in to some variable

Last edited by lmadhuri; 02-07-2007 at 08:15 AM.. Reason: enhancement in requirement
# 2  
Old 02-07-2007
Quote:
Originally Posted by lmadhuri
how do we retrieve a line from a file in unix
Do you want to retrieve a line based on a pattern ?
Code:
grep "pattern" file

or do you want to read file line by line ?
Code:
while read line
do
      echo $line
done < file

# 3  
Old 02-07-2007
thanks for the quick response

hi .... anbu23

got muchwork done by ur info..

cheers Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep: Retrieve two strings from one file to find them anyone on line in another file

I am having trouble matching *two* strings from one file anywhere in a line of a second file, and could use some help getting this figured out. My preference would be to use grep for this because I would like to take advantage of its -A option. The latter is due to the fact that I would like both... (2 Replies)
Discussion started by: jvoot
2 Replies

2. Homework & Coursework Questions

awk command to retrieve record 23 and 89 from UNIX file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file?... (6 Replies)
Discussion started by: rakeshp
6 Replies

3. UNIX for Beginners Questions & Answers

awk command to retrieve record 23 and 89 from UNIX file

Hi Everyone, I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file? Please let me know what is the awk command for this? Regards Rakesh (1 Reply)
Discussion started by: rakeshp
1 Replies

4. Shell Programming and Scripting

How to retrieve a file from specific path using unix script?

Hi i'm new to shell script, i want to get the filename from specific location which i mentioned in my script. The scirpt should read the filename exactly using the following command "ls -ltr | tail -1". Could someone show me on this. Below is my script #!/bin/ksh PATH= /usr/ if then ... (4 Replies)
Discussion started by: fresher
4 Replies

5. Shell Programming and Scripting

Retrieve string from each line in a file based on a pattern in Unix

I have a file which contains several lines. Sample content of the file is as below. OK testmessage email<test@123> NOK receivemessage email<123@test> NOK receivemessage email(123@test123) NOK receivemessage email<abc@test> i would like to know by scripting will... (10 Replies)
Discussion started by: ramasar
10 Replies

6. UNIX for Dummies Questions & Answers

retrieve every 4th line from a file

Hello, I want to retrieve 2, 6, 10, 14...... (each 4 lines apart) from a file that looks like the sample below. In other words, I want only lines corresponding to the Xs. Header1_a XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Header1_b yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy Header2_a... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

7. UNIX for Dummies Questions & Answers

How to retrieve a particular line from a file

Hi, I want to retrieve a particular line from a file and print its content to a file. Can you suggest how to do it in UNIX ?. Rgds vinayap (2 Replies)
Discussion started by: vinayap
2 Replies

8. Shell Programming and Scripting

search and retrieve previous line in file

I've got a file with the following layout: #STMP FSgroup filename /filesysname1 filestatus 2 #STMP FSstatus filename /filesysname1 ratio 30 #STMP FSgroup filename ... (2 Replies)
Discussion started by: paulsew
2 Replies

9. UNIX for Dummies Questions & Answers

(cont) Retrieve line from a file based on a value in specific column

HI, Your help was great: awk -F":" '$5 ~ /^P/{print }' file I would like to know what changes need to be done to this line code, so that I can put it in a shell script and call it as the example below. example: countries that start with chacater 'P' > country P Result: ... (0 Replies)
Discussion started by: efernandes
0 Replies

10. UNIX for Dummies Questions & Answers

Retrieve line from a file based on a value in specific column

Hi, I have a file that has several values seperated by ":" 2006:John:Student:Football:Portugal:Cinema 2006:James:Engineer:Basket:Poland:Theatre 2007:Lucy:Diver:Gymnastic:England:Music 2007:Smith:Plumber:Basket:Spain:Poker I need make a filter based on the 5th field to find countries that... (1 Reply)
Discussion started by: efernandes
1 Replies
Login or Register to Ask a Question