The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Read a file line by line VENC22 UNIX for Dummies Questions & Answers 4 10-30-2008 11:09 AM
read the file line by line kittusri9 Shell Programming and Scripting 3 04-24-2008 08:26 AM
Read file then grep the line mr_bold Shell Programming and Scripting 2 02-07-2008 03:33 AM
How to read last line of a txt file? yongho UNIX for Dummies Questions & Answers 2 06-13-2005 01:20 PM
read line from file rein Shell Programming and Scripting 5 04-15-2005 02:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2005
spaceship spaceship is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 4
How to read from a file line by line and do stuff

I want to read from a file and then do some stuff based on the text read from each line. Basically it is a list of usernames and I need to read each user, check it exist in passwd and extract their home directory and then copy a few files to that users home directory. Then move onto the next user in the file. Is this possible ??
  #2 (permalink)  
Old 03-17-2005
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
for i in `cat filename.txt`
do
grep $i /etc/passwd
etc
etc
done
  #3 (permalink)  
Old 03-17-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by spaceship
I want to read from a file and then do some stuff based on the text read from each line. Basically it is a list of usernames and I need to read each user, check it exist in passwd and extract their home directory and then copy a few files to that users home directory. Then move onto the next user in the file. Is this possible ??
Here's a quick and sloppy way of doing it in KSH.
Code:
{
typeset IFS='
'
while read USER_NAME
do
   USER_DIR=$(grep $USER_NAME /etc/passwd | awk -F: '{print $6}')                                                                                                 
   print $USER_DIR                                                                                                                                                 
done < /etc/passwd
}
  #4 (permalink)  
Old 03-17-2005
spaceship spaceship is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 4
Cool

Thank you both for your help. Sorted
  #5 (permalink)  
Old 03-17-2005
chaandana chaandana is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 49
This will do

FileName='specify your file here'
while read LINE
do
echo $LINE
#do your stuff here
done < $FileName
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0