The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cut last line of a word bullz26 Shell Programming and Scripting 2 03-18-2008 08:42 AM
how to move word by word on command line pbsrinivas UNIX for Dummies Questions & Answers 1 11-23-2007 03:17 AM
Need to replace the first word of a line if it occurs again in the next line(shell) geeko Shell Programming and Scripting 1 09-25-2007 07:15 AM
put each word in new line - sed or tr hemangjani Shell Programming and Scripting 3 09-13-2006 11:06 AM
Can a shell script pull the first word (or nth word) off each line of a text file? tricky Shell Programming and Scripting 5 08-17-2006 03:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-01-2008
Registered User
 

Join Date: Mar 2008
Posts: 27
Angry Read line by line not word by word

i have this line

my,name,is,john

stored in a file d.sh and i wish to print the line as string..but im getting word by word...have tried this.........

for in $(cat $d.sh);
do
echo $i
done

but this is giving me
my
name
is
john
Reply With Quote
Forum Sponsor
  #2  
Old 03-01-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
use a while loop
Code:
while read -r line
do
 echo "$line"
done  < "yourfile"
Reply With Quote
  #3  
Old 03-01-2008
Registered User
 

Join Date: Mar 2008
Posts: 27
Quote:
Originally Posted by ghostdog74 View Post
use a while loop
Code:
while read -r line
do
 echo "$line"
done  < "yourfile"

thanx a lot ghostdog that was straight forward really appreciate it!

if i have 2 files to compare the lines how do i do it with the While loop
say file 1 has
my name is john
file2
my name is jon
i want to compare if the lines in each file are the same
have tried

cat 'file.1' | while read line;
do
c=$line
cat 'file.2' | while read line
do
d=$line
if test "$c" != "$d"
then echo $c is different
fi
done
done

prints continously
Reply With Quote
  #4  
Old 03-01-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
if all you want is to compare lines in 2 files , you can use diff. check the diff man page
Reply With Quote
  #5  
Old 03-01-2008
Registered User
 

Join Date: Mar 2008
Posts: 27
Quote:
Originally Posted by ghostdog74 View Post
if all you want is to compare lines in 2 files , you can use diff. check the diff man page
thanx mate i have been using the diff , cmp, comm and patch but with the files i was doing include an md5sum but still the outcome isnt true thus trying to do it manually with the while loop......if u get a chance just correct me in the While loop
Reply With Quote
  #6  
Old 03-01-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
you could just show some sample input files.
Reply With Quote
  #7  
Old 03-02-2008
Registered User
 

Join Date: Mar 2008
Posts: 4
or add the Internal Field Seperator to ur For loop code

IFS=$'\n'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0