LinuxQuestions.org
Help answer threads with 0 replies.
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 05-23-2009, 08:26 AM   #1
mivison
LQ Newbie
 
Registered: Jan 2007
Location: Kennedale,Texas
Distribution: Mepis,Puppy
Posts: 22

Rep: Reputation: 15
executing a text file one line at a time with bash? (solved)


i'm trying right a bash script so i can read a text file one line at a time to executed it with a music editor i have. here is an example of part of the script( i'm new at this script stuff). what am i doing wrong?

number=0
until [ $number -ge 100 ]; do
transcribe $(head -n $number save.txt | tail -n 1)&
number=$((number + 1))

Last edited by mivison; 05-23-2009 at 03:06 PM. Reason: solved
 
Old 05-23-2009, 08:40 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Without knowing what happens, it's pretty hard to say what's wrong.

Your are missing a "done" at the end of the "until--do" loop.

I assume that transcribe is an executable command---Does it work if you do this one line by itslef in a terminal?
 
Old 05-23-2009, 08:49 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I agree with pixellany: please tell us what does not work (error message, missing output, wrong output and so on).

Last edited by colucix; 05-23-2009 at 08:51 AM. Reason: my mistake...
 
Old 05-23-2009, 08:54 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I think the "until" loop is OK.......

until number >= x

is the same as:

while number is < x
 
Old 05-23-2009, 09:03 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by pixellany View Post
I think the "until" loop is OK.......

until number >= x

is the same as:

while number is < x
Correct. I've already changed my post. Thx.
 
Old 05-23-2009, 09:11 AM   #6
mivison
LQ Newbie
 
Registered: Jan 2007
Location: Kennedale,Texas
Distribution: Mepis,Puppy
Posts: 22

Original Poster
Rep: Reputation: 15
sorry about the lack of info. yes i do put do put "done" in there. what happens is i get an endless loop. it keeps executing the last line over and over again.

thanks for the quick replies guys!
 
Old 05-23-2009, 09:40 AM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
That's really odd. What happen if you copy/paste and execute the following script?
Code:
#!/bin/bash
number=0
until [ $number -ge 100 ]
do
  echo $number
  ((number++))
done
You sure there is no typo in the increment statement, so that the variable "number" is not actually updated?

Last edited by colucix; 05-23-2009 at 09:52 AM.
 
Old 05-23-2009, 09:46 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
This works:
Code:
!/bin/bash

number=0
until [[ $number -ge 20 ]]; do
        echo $number
        number=$(($number + 1))
done
Could it have something to do with the "&" at the end of the transcribe statement?
 
Old 05-23-2009, 10:05 AM   #9
mivison
LQ Newbie
 
Registered: Jan 2007
Location: Kennedale,Texas
Distribution: Mepis,Puppy
Posts: 22

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
This works:
Code:
!/bin/bash

number=0
until [[ $number -ge 20 ]]; do
        echo $number
        number=$(($number + 1))
done
Could it have something to do with the "&" at the end of the transcribe statement?

if i don't use the "&", i have to execute them one at at a time by the pressing enter key. is there a way i could read how many lines are in the text file so i can put the sum in a variable?
 
Old 05-23-2009, 03:09 PM   #10
mivison
LQ Newbie
 
Registered: Jan 2007
Location: Kennedale,Texas
Distribution: Mepis,Puppy
Posts: 22

Original Poster
Rep: Reputation: 15
either one of these work

transcribe $(sed -n -e '/1/,/100/p' save.txt) &

transcribe $(head -n100 save.txt) &
 
Old 05-23-2009, 03:43 PM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Have you tried the until loop with the echo command, in place of transcribe? What is the result?
 
Old 05-23-2009, 06:43 PM   #12
mivison
LQ Newbie
 
Registered: Jan 2007
Location: Kennedale,Texas
Distribution: Mepis,Puppy
Posts: 22

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
Have you tried the until loop with the echo command, in place of transcribe? What is the result?
yes i did and there seems to be a problem with that command on my eeepc. i am running puppy 4.20 on that netbook. i wonder what the problem could be?
 
Old 05-23-2009, 07:48 PM   #13
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by mivison View Post
yes i did and there seems to be a problem with that command on my eeepc. i am running puppy 4.20 on that netbook. i wonder what the problem could be?
Again, you need to tell us WHAT problem.....

I recommend doing some tests with individual commands to confirm that they behave as expected. As soon as you find an anomaly, post exactly what happens.
 
Old 05-23-2009, 09:18 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
It sounds like you have a list of records in save.txt that you want automatically processed, without human interaction:
Code:
IFS="
" # ie put a single <return> in between the quotes
for rec in `cat save.txt`   # backquotes, not single quotes
do
    nohup transcribe $rec &    # nohup plus & enables you to logout of this session without breaking it
done
 
Old 05-24-2009, 12:54 AM   #15
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Quote:
running puppy 4.20 on that netbook
get a real Linux on there with rools that work like they are supposed to....
 
  


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
bash: replace a line in text file freeindy Programming 10 09-08-2011 12:08 PM
Deleting empty line at end of text file in BASH human2.0 Linux - General 8 04-01-2009 02:44 AM
bash : read every line from text file starting at given line number quadmore Programming 4 02-20-2009 12:29 PM
bash - read or write to specific line in text file? babag Programming 11 08-23-2008 01:44 PM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM

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

All times are GMT -5. The time now is 11:26 AM.

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