Sponsored Content
Top Forums Shell Programming and Scripting BASH: File name part to list reference problem. Post 302441616 by SilversleevesX on Sunday 1st of August 2010 08:22:06 PM
Old 08-01-2010
Question BASH: File name part to list reference problem.

I've made a habit of including a four-letter "tail" on image file names I download from the Web, so I can both match them with IPTC Transmission References of my own making and rename them later using either a GUI renamer or a script I've written myself. Now I want to automate the process of writing the TRs to the files by way of Exiv2, leaving just the renaming stage of my routine before moving on to "filing them away" in categorized subfolders, CDs, etc.

Using OpenOffice Calc, I was able to create a list of these four-letter suffixes and the TRs to which they correspond, sort by the former and output to a text file. I added an extra field of IPTC Categories (also of my own making -- doesn't seem to matter when Categories is in the process of being dropped from the IIM). The script I have works with one file at a time, as my line-by-line command-line tests in a terminal emulator have proven, but something goes haywire when applied (as I have done so) to a whole folder of files and the complete list of suffixes, TRs and categories all at once.

I doubt I'm either using the right loop types to process this data, nor am I at all sure that I have the loops that are there nested correctly in the script. The output I've got so far happens to be the "natural" name of the last suffix in the list. What I want is the "natural" name corresponding to the suffix of the file being "looked at" by the script.

Here's the script as it reads so far:
Code:
for a in $(ls *.jpg); # Find files ending in "jpg" in the current directory
do
	bargirl=$(echo $a)
	while read 'line';
	do
		souse=$(echo $line)
		drunk=${souse%:*}
		verydrunk=$(echo $souse | cut -d":" -f2)
		firstdrink=$(echo $verydrunk | cut -d, -f1)
		seconddrink=$(echo $verydrunk | cut -d, -f2)
		thirddrink=$(echo $verydrunk | cut -d, -f3)
done<downloads-xreference.txt # The text file with the three columns (suffix, natural name and Category). Terminate the 'while read' loop
jackdaniels=$(echo ${bargirl:(-4)}) # Take the ".jpg" off the file name	
singlemalt=$(echo $bargirl | cut -d'.' -f1) # Ditto
puregrain=$(echo ${singlemalt%????}) # Now strip the suffix off -- comes from the renaming script
jimbeam=$(echo ${singlemalt:(-4)}) # "What was that suffix code again?"
if [[ $jimbeam -eq $seconddrink ]]; # Does it exist in column 3 of the text file? Does it match the one on the file we're looking at? 
then
	chaser=$firstdrink # Variable "chaser" should be the matched 4-letter suffix.
	echo $chaser # "Show me the money."
fi
done #Terminates the 'for' loop

BZT
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

BASH: Grepping/sedding/etc out part of a file... (from one word to 'blank' line)

I have a file that lists data about a system. It has a part that can look like: the errors I'm looking for with other errors: Alerts Password Incorrect Login Error Another Error Another Error 2 Other Info or, just the errors I need to parse for: Alerts Password Incorrect ... (9 Replies)
Discussion started by: elinenbe
9 Replies

2. Shell Programming and Scripting

How to select or make reference to, part of a field

For a field format such as AAL1001_MD82, how do I select(and use in if statement) only the last four elements( in this case MD82) or the first three elements (in this case AAL)? For instance, how do I do the following - if first three elements of $x == yyy, then ... (5 Replies)
Discussion started by: akshaykr2
5 Replies

3. Shell Programming and Scripting

Array reference problem

i have a variable MYHOST that has my host name.depending on the host i have an array like A_<hostname>.Everytime i need to append the hostname to A_ to get the array.but in the shell script i am nt able to access the members of that array. code of what i hav done: export temp=A_$MYHOST for... (15 Replies)
Discussion started by: niteesh_!7
15 Replies

4. Shell Programming and Scripting

BASH - Reference external variable name dynamically

Hi there, I have included an external properties file into my BASH script via the 'source' command. I am attempting to dynamically assign a variable in the BASH script, that references the variable name within the external properties file i.e. #!/bin/bash pth=${0%/*} source... (3 Replies)
Discussion started by: mjwoodford
3 Replies

5. Shell Programming and Scripting

Replace character based on reference file problem asking

I got two files right now, input file (target file), reference file 1 (query file) reference file 1 (long list of data) KOLOPWMOPOPO ADASDASD ADSASDASDAD . . target file (one long liner content) ADASDASDTYUKOKOLOPWMOPOPOOPLUAADSASDASDADPOPOUYADADASDASD desired output file content ... (1 Reply)
Discussion started by: patrick87
1 Replies

6. Shell Programming and Scripting

Help with rename header content based on reference file problem

I got long list of reference file >data_tmp_number_22 >data_tmp_number_12 >data_tmp_number_20 . . Input file: >sample_data_1 Math, 5, USA, tmp SDFEWRWERWERWRWER FSFDSFSDFSDGSDGSD >sample_data_2 Math, 15, UK, tmp FDSFSDFF >sample_data_3 Math, 50, USA, tmp ARQERREQR . . Desired... (7 Replies)
Discussion started by: perl_beginner
7 Replies

7. Shell Programming and Scripting

symbol list reference

Can anyone direct me to a page that holds a list of perl's built in symbols? Example: $_ means blah $? means blah2 $! means blah3 (3 Replies)
Discussion started by: mrwatkin
3 Replies

8. Programming

Passing Pointers by reference in C++ Problem

Hello All, I am having this issue...where I am actually having hard time understanding the problem: The code is as follows: #include<iostream.h> void fxn(char*** var) { int i =4; *var = (char**)malloc(i*sizeof(char*)); for(int j =0; j<4; j++) { *var = "name"; cout<<*var;... (6 Replies)
Discussion started by: mind@work
6 Replies

9. Shell Programming and Scripting

Shell Scripting Problem - Invalid Back Reference

Here is the question... Create a new script, sub2, taking three parameters... 1.) the string to be replaced 2.) the string with which to replace it 3.) the name of the file in which to make the substitution ...that treats the string to be replaced as plain text instead of as a regular... (1 Reply)
Discussion started by: johnhisenburg
1 Replies

10. Shell Programming and Scripting

Bash compare a list of file

Dear all, I believe this is a Bash basic question... I am bit ashamed for asking actually... I want to create a Bash script that compares 2 different folders: 1) work_folder and 2) work_folder.git #!/bin/bash FOLDER_NAME=`pwd | awk -F/ '{ print $NF }' | awk -F. '{ print $1 }'` ... (6 Replies)
Discussion started by: freddie50
6 Replies
SCRIPT(1)						    BSD General Commands Manual 						 SCRIPT(1)

NAME
script -- make typescript of terminal session SYNOPSIS
script [-akq] [-t time] [file [command ...]] DESCRIPTION
The script utility makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out later with lpr(1). If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is saved in the file typescript. If the argument command is given, script will run the specified command with an optional argument vector instead of an interactive shell. The following options are available: -a Append the output to file or typescript, retaining the prior contents. -k Log keys sent to program as well as output. -q Run in quiet mode, omit the start and stop status messages. -t time Specify time interval between flushing script output file. A value of 0 causes script to flush for every character I/O event. The default interval is 30 seconds. The script ends when the forked shell (or command) exits (a control-D to exit the Bourne shell (sh(1)), and exit, logout or control-D (if ignoreeof is not set) for the C-shell, csh(1)). Certain interactive commands, such as vi(1), create garbage in the typescript file. The script utility works best with commands that do not manipulate the screen. The results are meant to emulate a hardcopy terminal, not an addressable one. ENVIRONMENT
The following environment variable is utilized by script: SHELL If the variable SHELL exists, the shell forked by script will be that shell. If SHELL is not set, the Bourne shell is assumed. (Most shells set this variable automatically). SEE ALSO
csh(1) (for the history mechanism). HISTORY
The script command appeared in 3.0BSD. BUGS
The script utility places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects. It is not possible to specify a command without also naming the script file because of argument parsing compatibility issues. When running in -k mode, echo cancelling is far from ideal. The slave terminal mode is checked for ECHO mode to check when to avoid manual echo logging. This does not work when in a raw mode where the program being run is doing manual echo. BSD
January 22, 2004 BSD
All times are GMT -4. The time now is 10:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy