LinuxQuestions.org
Review your favorite Linux distribution.
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 07-05-2006, 08:15 AM   #1
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Rep: Reputation: 15
Eof


I wrote a simple code (part of the entire code) to parse a file. Each line is parsed in a loop over here.

but when i run this script, i get an error that done unexpected??? if i remove that (shouldnt though) then i get error _EOF1_ not found.

am i missing some rules over here

Code:
command=`cat << _EOF1_ 
cat $DATA_FILE|while read LINE
 do
    var1=`echo $LINE | awk -F"|" '{print$1}'`
    var2=`echo $LINE | awk -F"|" '{print$2}'`
    var3=`echo $LINE | awk -F"|" '{print$3}'`
    var4=`echo $LINE | awk -F"|" '{print$4}'`
    var5=`echo $LINE | awk -F"|" '{print$5}'`
    var6=`echo $LINE | awk -F"|" '{print$6}'`
    var7=`echo $LINE | awk -F"|" '{print$7}'`
    var8=`echo $LINE | awk -F"|" '{print$8}'`
    var9=`echo $LINE | awk -F"|" '{print$9}'`
    var10=`echo $LINE | awk -F"|" '{print$10}'`
    var11=`echo $LINE | awk -F"|" '{print$11}'`
done
_EOF1_`
 
Old 07-05-2006, 08:46 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
What are you trying to accomplish with the command= and EOF stuff?

Running the code just as:

Code:
cat $DATA_FILE|while read LINE
 do
    var1=`echo $LINE | awk -F"|" '{print$1}'`
    var2=`echo $LINE | awk -F"|" '{print$2}'`
    var3=`echo $LINE | awk -F"|" '{print$3}'`
    var4=`echo $LINE | awk -F"|" '{print$4}'`
    var5=`echo $LINE | awk -F"|" '{print$5}'`
    var6=`echo $LINE | awk -F"|" '{print$6}'`
    var7=`echo $LINE | awk -F"|" '{print$7}'`
    var8=`echo $LINE | awk -F"|" '{print$8}'`
    var9=`echo $LINE | awk -F"|" '{print$9}'`
    var10=`echo $LINE | awk -F"|" '{print$10}'`
    var11=`echo $LINE | awk -F"|" '{print$11}'`
done
Would make the loop work successfully (assuming you had $DATA_FILE previously defined in your shell or the script).

If you are trying to define a command to be used elsewhere within the script just do a man on bash and have a look at the "function" description.

Last edited by MensaWater; 07-05-2006 at 08:48 AM.
 
Old 07-05-2006, 08:48 AM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Your logic is not clear.
Code:
command=`cat $DATA_FILE|while read LINE
 do
    var1=`echo $LINE | awk -F"|" '{print$1}'`
    var2=`echo $LINE | awk -F"|" '{print$2}'`
    var3=`echo $LINE | awk -F"|" '{print$3}'`
    var4=`echo $LINE | awk -F"|" '{print$4}'`
    var5=`echo $LINE | awk -F"|" '{print$5}'`
    var6=`echo $LINE | awk -F"|" '{print$6}'`
    var7=`echo $LINE | awk -F"|" '{print$7}'`
    var8=`echo $LINE | awk -F"|" '{print$8}'`
    var9=`echo $LINE | awk -F"|" '{print$9}'`
    var10=`echo $LINE | awk -F"|" '{print$10}'`
    var11=`echo $LINE | awk -F"|" '{print$11}'`
done`
What might be a better question- what are you trying to do? When this completes $command will be empty unless you've redirected stderr
 
Old 07-05-2006, 09:18 AM   #4
tostay2003
Member
 
Registered: Jun 2006
Posts: 126

Original Poster
Rep: Reputation: 15
I gave only part of the code to avoid confusion but on contrary it has created more confusion.

Code:
command=`cat << _EOF1_ 
cat $DATA_FILE|while read LINE
 do
    var1=`echo $LINE | awk -F"|" '{print$1}'`
    var2=`echo $LINE | awk -F"|" '{print$2}'`
    var3=`echo $LINE | awk -F"|" '{print$3}'`
    var4=`echo $LINE | awk -F"|" '{print$4}'`
    var5=`echo $LINE | awk -F"|" '{print$5}'`
    var6=`echo $LINE | awk -F"|" '{print$6}'`
    var7=`echo $LINE | awk -F"|" '{print$7}'`
    var8=`echo $LINE | awk -F"|" '{print$8}'`
    var9=`echo $LINE | awk -F"|" '{print$9}'`
    var10=`echo $LINE | awk -F"|" '{print$10}'`
    var11=`echo $LINE | awk -F"|" '{print$11}'`
    ##example of statement which i plan to use
    SQL=`echo select ${var1} from ${var11}`
    ${SQL}
done
_EOF1_`
and then next from a interactive program i want to call ${command}
 
Old 07-05-2006, 10:11 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
You reinvented the concept of a function.

Try this instead:
Code:
command1 () {
  #
  # What follows here, was pasted from jlightner's post.
  #
  cat $DATA_FILE|while read LINE
   do
      var1=`echo $LINE | awk -F"|" '{print$1}'`
      var2=`echo $LINE | awk -F"|" '{print$2}'`
      var3=`echo $LINE | awk -F"|" '{print$3}'`
      var4=`echo $LINE | awk -F"|" '{print$4}'`
      var5=`echo $LINE | awk -F"|" '{print$5}'`
      var6=`echo $LINE | awk -F"|" '{print$6}'`
      var7=`echo $LINE | awk -F"|" '{print$7}'`
      var8=`echo $LINE | awk -F"|" '{print$8}'`
      var9=`echo $LINE | awk -F"|" '{print$9}'`
      var10=`echo $LINE | awk -F"|" '{print$10}'`
      var11=`echo $LINE | awk -F"|" '{print$11}'`
  done
}
After doing
Code:
bash$ source /path/to/the/script.sh
you can just do:
Code:
bash$ command1
 
  


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
EOF and \n exvor Programming 4 12-27-2005 02:20 PM
finding the eof nodger Programming 12 11-26-2004 02:17 AM
Premature EOF? miknight Programming 1 04-04-2004 12:19 AM
eof ... c ... linux xviddivxoggmp3 Programming 6 03-31-2004 12:56 PM
<< Eof ? sikandar Linux - Software 5 09-18-2003 11:39 AM

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

All times are GMT -5. The time now is 03:00 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