Sponsored Content
Top Forums Shell Programming and Scripting awk - ignore metacharacters, search shell variables Post 302659375 by DSommers on Wednesday 20th of June 2012 08:16:14 PM
Old 06-20-2012
Thanks Chubler XL, ygemici.

I've carefully copied and pasted your codes, they do not return any result.
I'm using the debian version of awk (mawk), does that affect your suggestions?

Thank you for trying. I'm going to give it one last attempt to try and combine your suggestions into one.

1. The best way to avoid metacharacters is to use the 'index' function
2. The best way to approach comparing 2 files is to use an 'array'

With that in mind, to simplify, i've made all files tab seperated and removed the .mp3 .

Use 2 arrays from file1 "Playlist"...
  • a for <field1> "Artist"
  • t for <field2> "Title"
Example Line from Playlist;
  • Shaggy Angel (Bonus Track)

Then;
1. compare the indexed Title "Angel (Bonus Track)" to file2 "Master-Music-List" <field2> "Title"
2. check that the indexed Artist "Shaggy" matches "Master-Music-List" <field1> "Artist"

If 'both' array1 (title) , and array2 (artist) match, then print the result.

Example;

Match this from "Playlist" to "Master-Music-List";
  • Shaggy Angel (Bonus Track)
Master-Music-List Lines:
  • Shaggy Angel (Bonus Track) 32000 /Music/S/Shaggy/Angel (Bonus Track.mp3
  • The Rolling Stones Angel 128000 /Music/R/Rolling Stones/Angel.mp3

This way, the song 'Angel (Bonus Track)' will match for Shaggy and not for Rolling Stones.

Could someone please help to include the arrays and index functions ?

Thank you.

Last edited by DSommers; 06-21-2012 at 10:37 AM.. Reason: refined formatting
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using shell variables In awk

Oh its not my day for syntax... cat gzipsize.txt | awk '{print "echo",$1,$2} > master.txt I have read a lot about the awk -v but haven't been able to get it to work. I have a variable in my script and I'm looking just to push it into the awk after the $2 (or anywhere would do)!!! Every... (11 Replies)
Discussion started by: nortypig
11 Replies

2. Shell Programming and Scripting

Modify shell variables with AWK

Dear Folks, I have a command output something like: And I want to store PIN0 and SIG0 in two shell variables, now I do a double awk: PIN=`gsmctl -d /dev/ttyS0 pin sig | awk '/PIN0/ { print $2}'` SIG=`gsmctl -d /dev/ttyS0 pin sig | awk '/SIG0/ { print $2}'` It's possible to... (4 Replies)
Discussion started by: Santi
4 Replies

3. Shell Programming and Scripting

Awk, shell variables

Hello, I've been trying to figure out how to use variables inside the AWK command and use it back in the korn shell sript. in my script I have lots of awk commands like this grep Listen /etc/ssh/sshd_config | \ awk '{ if ($2 == "22" ) print "OK"; else print "not OK" }' ... (3 Replies)
Discussion started by: mirusko
3 Replies

4. Shell Programming and Scripting

search and replace using awk with variables

Hi, I have been trying to use awk with variables that needs to search for a pattern and replace it with another pattern, the patterns are supplied in a variable. I have tried several different ways without success and hope that someone can help me. Here are the details echo $UPC 07007457809... (2 Replies)
Discussion started by: jerardfjay
2 Replies

5. UNIX for Advanced & Expert Users

use of variables in awk to search for pattern from a file

Hi, I need to extract all the content between two strings stored in two variables "startstring" and "endstring" startstring=hello enstring=world #notworking awk '/$startstring/, $NF ~ /$endstring/ ' file > file2 The above code is not working with variables. It works when actual string... (2 Replies)
Discussion started by: jeanjkj
2 Replies

6. Shell Programming and Scripting

awk - take variables out to shell

Hi, How could we take the value of awk variables out to shell? I know the following methods 1. awk '{print $1}' < file | read a echo $a 2. a=`awk '{print $1}' < file` echo $a Please let me know if there are any other methods. Also, how do we take more than 1 variable value... (4 Replies)
Discussion started by: Thumban
4 Replies

7. Shell Programming and Scripting

escaping metacharacters in paths for a shell command

I have a file which contains a list of paths separated by a new line character. e.g /some/path/to/a/file.png /some/path to/another/file.jpeg /some path/to yet/another/file Notice that these paths may contain metacharacters, the spaces for example are also not escaped. If I wanted... (5 Replies)
Discussion started by: cue
5 Replies

8. Shell Programming and Scripting

awk search/replace specific field, using variables for regexp & subsitution then overwrite file

Hello, I'm trying the solve the following problem. I have a file which I intend to use as a csv called master.csv The columns are separated by commas. I want to change the text on a specific row in either column 3,4,5 or 6 from xxx to yyy depending upon if column 1 matches a specified pattern.... (3 Replies)
Discussion started by: cyphex
3 Replies

9. UNIX for Dummies Questions & Answers

Command line not recognizing metacharacters in awk

Hello, I'm new to command line coding (and coding in general) and have run into a problem. I'm using awk to perform a global find and replace in a text file in the Terminal provided by Mac. Here is a sample of my textfile where the fields are separated by tabs. 1Ps 1,1 VWB/(J VWB VWB... (7 Replies)
Discussion started by: jvoot
7 Replies

10. Shell Programming and Scripting

Using Shell variables in awk

Hi All, I have a file which I am reading and looking for "EXIT" statement. I want to insert ":JCWPROD" after each EXIT statement only if ":JCWPROD" doesn't exist. Here is the sample file : EXIT Testing EXIT tesing123 EXIT Desired file : EXIT :JCWPROD Testing EXIT :JCWPROD... (7 Replies)
Discussion started by: nua7
7 Replies
tracker-sparql(1)						   User Commands						 tracker-sparql(1)

NAME
tracker-sparql - Use SparQL to query the Tracker databases. SYNOPSIS
tracker-sparql [OPTION...] [-q QUERY] | [-f FILE] DESCRIPTION
tracker-sparql allows the caller to run an RDF query on the database. This can be done two ways. Either by providing a FILE with the query or by providing a string with the QUERY string. The FILE argument can be either a local path or a URI. It also does not have to be an absolute path. OPTIONS
-?, --help Show summary of options. -f, --file=FILE Use a FILE with SPARQL content to query or update. -q, --query=SPARQL Use a SPARQL string to query the database with. -u, --update This has to be used with --query. This tells tracker-sparql to use the SPARQL update extensions so it knows it isn't a regular data lookup request. So if your query is intended to change data in the database, this option is needed. -c, --list-classes Returns a list of classes which describe the ontology used for storing data. These classes are also used in queries. For example, http://www.w3.org/2000/01/rdf-schema#Resource is one of many classes which should be returned here. -x, --list-class-prefixes Returns a list of classes and their related prefixes. Prefixes are used to make querying a lot simpler and are much like an alias. For example, http://www.w3.org/2000/01/rdf-schema#Resource has the prefix rdfs so queries can be cut down to: "SELECT ?u WHERE { ?u a rdfs:Resource }" -p, --list-properties=CLASS Returns a list of properties which pertain to a class. You can use both formats here for the class, either the full name http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#Video or the shortened prefix name nfo:Video. This gives the following result: $ tracker-sparql -p nfo:Video Properties: 2 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameRate http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#frameCount These properties nfo:frameRate and nfo:frameCount can be used in more complex queries (see --query). -n, --list-notifies=CLASS Returns a list of classes which are notified over D-Bus about any changes that occur in the database. CLASS does not have to be sup- plied here. This is optional and filters the results according to any argument supplied. With no CLASS, all classes are listed. -s, --search=TERM Returns a list of classes and properties which partially match TERM in the ontology. This is a case insensitive match, for example: $ tracker-sparql -s text Classes: 4 http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#TextDocument http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PlainTextDocument http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#PaginatedTextDocument http://www.tracker-project.org/temp/nmm#SynchronizedText Properties: 5 http://www.tracker-project.org/ontologies/tracker#fulltextIndexed http://www.tracker-project.org/ontologies/tracker#fulltextNoLimit http://www.semanticdesktop.org/ontologies/2007/01/19/nie#plainTextContent http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#plainTextMessageContent http://www.tracker-project.org/temp/scal#textLocation -V, --version Print version. EXAMPLES
List all classes $ tracker-sparql -q "SELECT ?cl WHERE { ?cl a rdfs:Class }" List all properties for the Resources class (see --list-properties) $ tracker-sparql -q "SELECT ?prop WHERE { ?prop a rdf:Property ; rdfs:domain <http://www.w3.org/2000/01/rdf-schema#Resource> }" List all class namespace prefixes $ tracker-sparql -q "SELECT ?prefix ?ns WHERE { ?ns a tracker:Namespace ; tracker:prefix ?prefix }" List all music files $ tracker-sparql -q "SELECT ?song WHERE { ?song a nmm:MusicPiece }" List all music albums $ tracker-sparql -q "SELECT ?album ?title COUNT(?song) AS songs SUM(?length) AS totallength WHERE { ?album a nmm:MusicAlbum ; nie:title ?title . ?song nmm:musicAlbum ?album ; nfo:duration ?length } GROUP BY ?album" List all music from a particular artist $ tracker-sparql -q "SELECT ?song ?title WHERE { ?song nmm:performer [ nmm:artistName 'Artist Name' ] ; nie:title ?title }" Set the played count for a song $ tracker-sparql -u -q "DELETE { <file:///home/user/Music/song.mp3> nie:usageCounter ?count } WHERE { <file:///home/user/Music/song.mp3> nie:usageCounter ?count } INSERT { <file:///home/user/Music/song.mp3> nie:usageCounter 42 }" List all image files $ tracker-sparql -q "SELECT ?image WHERE { ?image a nfo:Image }" List all image files with a specific tag $ tracker-sparql -q "SELECT ?image WHERE { ?image a nfo:Image ; nao:hasTag [ nao:prefLabel 'tag' ] }" List all image files created on a specific month and order by date $ tracker-sparql -q "SELECT ?image ?date WHERE { ?image a nfo:Image ; nie:contentCreated ?date . FILTER (?date >= '2008-07-01T00:00:00' && ?date < '2008-08-01T00:00:00') } ORDER BY ?date" SEE ALSO
tracker-store(1), tracker-info(1). http://nepomuk.semanticdesktop.org/ http://www.w3.org/TR/rdf-sparql-query/ GNU
July 2009 tracker-sparql(1)
All times are GMT -4. The time now is 01:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy