for/while


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting for/while
# 1  
Old 06-04-2008
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  
Old 06-04-2008
while read line
do
echo $line
done < any

for i in 1 2 3
do
head -$i any | tail -1
done
# 3  
Old 06-04-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question