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.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-04-2008
jkl_jkl jkl_jkl is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 46
for/while

This is an example of one of my requirement:

Code:
$ cat any
A C F
D 4
A F C V

A)

$ while read line
> do
> echo $line
> done < any

A C F
D 4
A F C V

B)

$ for line in `cat any`
> do
> echo $line
> done

A
C
F
D
4
A
F
C
V
Using "for" how can I achieve the same output as while offers(A) ?
  #2 (permalink)  
Old 06-04-2008
siba.s.nayak siba.s.nayak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 161
while read line
do
echo $line
done < any

for i in 1 2 3
do
head -$i any | tail -1
done
  #3 (permalink)  
Old 06-04-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Try something like this:

Code:
OIFS=$IFS
IFS=""

for line in `cat any`
do
  echo $line
done

IFS=$OIFS
But I should go for the first example without cat.

Regards
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:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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