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
Help required with a Csh script to read data from a file fizzme Shell Programming and Scripting 1 05-29-2008 07:30 PM
how to read the data from an excel sheet and use those data as variable in the unix c Anne Grace UNIX for Advanced & Expert Users 1 03-03-2008 07:21 AM
How to read the configuration file from shell script nishanth hampal Shell Programming and Scripting 7 02-27-2008 03:42 AM
Howto capture data from rs232port andpull data into oracle database-9i automatically boss UNIX for Dummies Questions & Answers 1 09-23-2007 02:35 AM
Post Shell programming: Question about source a file and read data from the file ccwq Shell Programming and Scripting 3 08-04-2007 10:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-06-2006
banjo banjo is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 5
Howto read data into a shell script

Hi all,

I'm anew shell user, and want to now how to do that?
i have a files that have inside few raws of names of directories, i want to read only the lins that are a dir name how to do so.

the file looks like that
####################################
# This is the list of dirs files #
####################################
ver 1
upodate 01-01-2006
/usr
/etc
/usr/testing
/rama


i need to read only the files that start with /

thanks
  #2 (permalink)  
Old 09-06-2006
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Try something link:
cat <file> | grep ^/
  #3 (permalink)  
Old 09-06-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
why cat

Code:
grep ^/ filename | while read dirname
do
echo $dirname
done
would do
  #4 (permalink)  
Old 09-06-2006
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

Join Date: Mar 2006
Location: India
Posts: 255
If you want to search only for lines which starts from / then use this code

Code:
for input_dir_row in `cat your_file`
do
echo "$input_dir_row" |grep -s "^/">>/dev/null && echo "$input_dir_row "
done
  #5 (permalink)  
Old 09-06-2006
vish_indian vish_indian is offline
Registered User
  
 

Join Date: Jun 2006
Location: Delhi, India
Posts: 92
Any of the 2 will do

####################################
# This is the list of dirs files #
####################################
ver 1
upodate 01-01-2006
/usr
/etc
/usr/testing
/rama


Code:
grep '^/' data
/usr
/etc
/usr/testing
/rama

Code:
awk '$1~"^/"' data
/usr
/etc
/usr/testing
/rama
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 12:54 PM.


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