LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-02-2006, 01:03 PM   #1
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Rep: Reputation: 15
KORN: Looping through output of command


In bash, I normally use this to read each line of output:

while read line
do
echo $line
done < <(cat /myfile.txt | cut -f1 -d" ")

But this doesn't fly in KSH. I can't find the same thing on any tutorials, doesn't anyone know how to do this in Korn?
 
Old 08-02-2006, 02:37 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Code:
#!/bin/ksh
cat /myfile.txt | cut -f1 -d" " | \
while read line
do
echo $line
done
 
Old 08-02-2006, 03:16 PM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
or with a closer syntax:
Code:
#!/bin/ksh
while read line
do
echo $line
done <<%
$(cat /etc/hosts | cut -f1 -d" ")
%
 
Old 08-03-2006, 11:15 AM   #4
eur0dad
Member
 
Registered: Jul 2006
Posts: 57

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jim mcnamara
Code:
#!/bin/ksh
cat /myfile.txt | cut -f1 -d" " | \
while read line
do
echo $line
done

This method works perfectly. The other one that was posted kept giving me "% unclosed" errors.
 
Old 08-03-2006, 02:57 PM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by eur0dad
The other one that was posted kept giving me "% unclosed" errors.
Huh ?

Please double check, it works for me with both the real ksh and pdksh.

You probably missed to copy the last line: "%"

Last edited by jlliagre; 08-03-2006 at 02:58 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the command that use to get these output shinwai Linux - Newbie 2 08-31-2005 08:26 AM
output from ls command Grafbak Programming 5 08-07-2005 05:35 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
' last -i ' command output praveenv Linux - Newbie 1 08-23-2004 02:14 PM
last -i command output praveenv Linux - Networking 2 08-18-2004 12:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration