The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep Multiple Strings durgaprasad Shell Programming and Scripting 10 06-26-2009 06:38 AM
grep strings of a certain length angela.perez7 Shell Programming and Scripting 2 02-14-2009 03:39 PM
want to grep only strings in a file? balan_mca Shell Programming and Scripting 5 11-03-2008 06:19 AM
number of lines returned from a grep command cesarNZ Shell Programming and Scripting 4 10-09-2008 09:57 PM
Copying file names returned from a grep command into another directory Kartheg UNIX for Dummies Questions & Answers 4 11-17-2005 12:34 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-20-2009
abhigyan91 abhigyan91 is offline
Registered User
  
 

Join Date: Jul 2009
Location: Goa, India
Posts: 9
downsizing of strings which are returned by grep

hey every1, i am a very new shell programmer. what i am trying to do is to rename a music file using its metadata(using mminfo)
the problem is, mminfo's output is very weird:
Quote:
abhigyan@abhigyan-laptop:~$ mminfo ~/Desktop/It\'s\ Not\ My\ Time.mp3
/home/abhigyan/Desktop/It's Not My Time.mp3
| title: It's Not My Time
| language: Undetermined
| langcode: und
| media: MEDIA_AUDIO
| artist: 3 Doors Down
| mime: audio/mpeg
| samplerate: 32000
| length: 243.173877551
| codec: MPEG Layer 3
| bitrate: 128
| fourcc: 0x55
| userdate: 2008
| album: 3 Doors Down
| genre: Rock
| mode: stereo
my final filename should be "$artist - $title"

however, when i use
Code:
artist=` mminfo ~/Desktop/It\'s\ Not\ My\ Time.mp3|grep artist`
echo $artist gives:
Quote:
| artist: 3 Doors Down
now i need to get rid of the " | artist: " part so i only have "3 Doors Down".
How do i do that? I tried reading man page for cut, but cudnt understand much

sorry for such a long post for a relatively simple problem
  #2 (permalink)  
Old 07-20-2009
ryandegreat25 ryandegreat25 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 236
try
Code:
artist=` mminfo ~/Desktop/It\'s\ Not\ My\ Time.mp3|grep artist | awk -F: '{print $2}'`
  #3 (permalink)  
Old 07-20-2009
abhigyan91 abhigyan91 is offline
Registered User
  
 

Join Date: Jul 2009
Location: Goa, India
Posts: 9
Yea.. it works thanks!!
Can you explain what that code does?
will it work for all song files assuming the appropriate meta-data is available?
  #4 (permalink)  
Old 07-20-2009
ryandegreat25 ryandegreat25 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 236
yes, i presume it will work. There are many ways to do this actually.

Code:
awk -F: '{print $2}'
The -F is the field separator specified with colon (: ) it prints the column 2 which is defined by print $2.

print $1 will print "| artist"
  #5 (permalink)  
Old 07-20-2009
abhigyan91 abhigyan91 is offline
Registered User
  
 

Join Date: Jul 2009
Location: Goa, India
Posts: 9
this is what i actually set out to do:

plz have a look at the code below.. Something is rong with line 17

Code:
#!/bin/bash


#Renames and organizes your music data.
#Provide the full path of your music folder as an argument.
#Renames music files according to its metadata  in format "Artist - Title". 
#Creates a folder with Artist name and stores file in it.


if [ -z $1 ];then #setting default directory
    cd /home/abhigyan/Desktop/testing
else    
    cd $1
fi

for F in ./*
    if [ -f $F ];then
        artist=`mminfo $F|grep artist|awk -F: '{print $2}'` #getting metadata
        chkartist=$? 
        title=`mminfo $F|grep title|awk -F: '{print $2}'`
        chktitle=$?
            if [ $chkartist -eq 0  ||  $chktitle -eq 0 ];then
                filename="$artist - $title"
                mv $F $filename
                    if [ -d $artist ];then    #moving file to the artist folder
                        mv $filename ./$artist  
                    else
                        mkdir $artist
                        mv $filename ./$artist
                    fi
            else
            echo -e "Skipping b/c insufficient metadata: $F \n"
            fi
    fi
done
Quote:
abhigyan@abhigyan-laptop:~$ bash meta.sh
meta.sh: line 17: syntax error near unexpected token `if'
meta.sh: line 17: ` if [ -f $F ];then'

Last edited by abhigyan91; 07-20-2009 at 03:14 AM.. Reason: i added what the shell returns on executing the script;also bold changes in script
  #6 (permalink)  
Old 07-20-2009
ryandegreat25 ryandegreat25 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 236
seems good.. can you the post the error?
  #7 (permalink)  
Old 07-20-2009
abhigyan91 abhigyan91 is offline
Registered User
  
 

Join Date: Jul 2009
Location: Goa, India
Posts: 9
edited:

abhigyan@abhigyan-laptop:~$ bash meta.sh
meta.sh: line 17: syntax error near unexpected token `if'
meta.sh: line 17: ` if [ -f $F ];then'
Reply

Bookmarks

Tags
cut, grep

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0