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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to replace the first word of a line if it occurs again in the next line(shell) geeko Shell Programming and Scripting 4 06-18-2009 03:36 PM
cut last line of a word bullz26 Shell Programming and Scripting 2 03-18-2008 11:42 AM
how to move word by word on command line pbsrinivas UNIX for Dummies Questions & Answers 1 11-23-2007 06:17 AM
put each word in new line - sed or tr hemangjani Shell Programming and Scripting 3 09-13-2006 03:06 PM
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 07:29 AM

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 03-01-2008
vadharah vadharah is offline
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
  #2 (permalink)  
Old 03-01-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
use a while loop

Code:
while read -r line
do
 echo "$line"
done  < "yourfile"

  #3 (permalink)  
Old 03-01-2008
vadharah vadharah is offline
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
  #4 (permalink)  
Old 03-01-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
if all you want is to compare lines in 2 files , you can use diff. check the diff man page
  #5 (permalink)  
Old 03-01-2008
vadharah vadharah is offline
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
  #6 (permalink)  
Old 03-01-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
you could just show some sample input files.
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 04:54 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