LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 12-24-2005, 06:55 PM   #1
palceksmuk
LQ Newbie
 
Registered: Dec 2005
Distribution: slackware 10.2
Posts: 26

Rep: Reputation: 15
bash script that can read lines of text


OK I hope I posted in the right forum because this is not real programming...

So now I've wrote this script that
-gets all the audio streams in an ogm file
-displays them and displays a menu so I can select from 1 to 3
-gets all the subtitle streams in an ogm file
-displays them and displays a menu so I can select from 1 to 3
-starts mplayer

Code:
#!/bin/bash
#filter ogminfo for lines that contain audio streams
AID=`ogminfo -v $1 | grep ") a" | grep -i LANGUAGE`
#display a menu so I can select the desidered stream
AUDIO=`kdialog --menu "$AID" 0 "audio a1" 1 "audio a2" 2 "audio a3"

#filter ogminfo for lines that contain subtitle streams
SID=`ogminfo -v $1 | grep ") t" | grep -i LANGUAGE`
#display a menu so I can select the desidered stream
SUBS=`kdialog --menu "$SID" 0 "subtitles t1" 1 "subtitles t2" 2 "subtitles t3"

#start mplayer
mplayer $1 -aid $AUDIO -sid $SUBS
But this is a little slow...probably because of kdialog...

So now I would like to modify the script so that instead of kdialog displaying the menu it would read the $AID variable and get the line that contains "Japanese" and then create a variable like -aid $LINENUMBER
and the same for subtitles just that it would search for the line that contains english.

I think that could be done with bash but I don't know how to loop trough lines and find which line contains the searched string?
 
Old 12-25-2005, 04:49 AM   #2
palceksmuk
LQ Newbie
 
Registered: Dec 2005
Distribution: slackware 10.2
Posts: 26

Original Poster
Rep: Reputation: 15
ok, after reading some samples on the internet I found something. I'll post it here, maybe it'll be useful for someone

Code:
#!/bin/bash
AID=`ogminfo -v $1 | grep ") a" | grep -i LANGUAGE`
echo "$AID" > /tmp/ogm.txt

FILETEK=/tmp/ogm.txt
n=0

for name in $(awk 'BEGIN{FS="="}{print $2}' < "$FILETEK" )
do
  echo "AID #$n = $name"
  if [[ $name = *Japanese* ]]
  then
      echo "-ok $n"
      AUDIO="-aid $n"
  fi
  let "n += 1"
done  

SID=`ogminfo -v $1 | grep ") t" | grep -i LANGUAGE`
echo "$SID" > /tmp/ogm.txt

m=0

for name in $(awk 'BEGIN{FS="="}{print $2}' < "$FILETEK" )
do
  echo "SID #$m = $name"
  if [[ $name = *English* ]] 
  then
      echo "-ok $m"
      SUBS="-sid $m"
  fi
  let "m += 1"
done  

echo "Audio: $AUDIO"
echo "Subtitles: $SUBS"

mplayer $AUDIO $SUBS $1


exit
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 read a given line number from text bendeco13 Programming 7 08-31-2012 04:49 PM
bash: read lines from a configuration script ldp Programming 2 09-23-2005 12:58 PM
bash script help to parse out text slack guy Linux - Newbie 3 12-30-2004 09:42 AM
Help with BASH script PLEASE READ!!! hroman Programming 7 10-08-2004 08:39 PM
Can't get lines of a file with a Bash script.. barisdemiray Programming 2 08-11-2004 01:42 PM


All times are GMT -5. The time now is 04:46 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration