Sponsored Content
Top Forums Shell Programming and Scripting Add unique identifier from file to filetype in directory Post 302986496 by Don Cragun on Friday 25th of November 2016 11:48:42 PM
Old 11-26-2016
I am fully aware that your current code only processes the contents of one directory. What I asked was whether or not you wanted your script to only process one directory. Since you didn't answer that question, the following script only processes one subdirectory of the directory /home/cmccabe/Desktop/index. (With changes to two lines and removal of a third line in this script, you can make it process files in all of the subdirectories instead of just processing files in one subdirectory.) The subdirectory is specified by an operand passed to your script (which defaults to R_2016_09_21_14_01_15_user_S5-00580-9-Medexome if no operand is given when you invoke this script).

Code:
#!/bin/bash
BaseDir=/home/cmccabe/Desktop/index
TranslationFile=/home/cmccabe/s5_files/identifier/input
SubDir=${1:-R_2016_09_21_14_01_15_user_S5-00580-9-Medexome}

cd "$BaseDir/$SubDir"
printf '%s\n' *.bam *.vcf | awk '
FNR == NR  {
	if(NF == 2)
		old[$2] = $1
	next
}
{	prefix = substr($0, 1, length($0) - 4)
	suffix = substr($0, length($0) - 3)
	if(prefix in old)
		printf("mv \"%s\" \"%s%s\"\n", $0, old[prefix], suffix)
	else	printf("# No translation found for \"%s\"\n", $0)
}' "$TranslationFile" -

which, with the sample data you provided, produces the output:
Code:
mv "MEV21.bam" "IonXpress_007.bam"
mv "MEV22.bam" "IonXpress_008.bam"
mv "MEV23.bam" "IonXpress_009.bam"
mv "MEV21.vcf" "IonXpress_007.vcf"
mv "MEV22.vcf" "IonXpress_008.vcf"
mv "MEV23.vcf" "IonXpress_009.vcf"

If you like the list of command produced by this script, run it again and pipe the output to a shell.

And, as always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Directory Inode Number Not Unique

Hi, I know that inode for each file is unique, but is it the for the directory? So far I found different directories has the same inode nubmer when you do ls -i, could some one explain why? Thanks a lot. (9 Replies)
Discussion started by: nj302
9 Replies

2. UNIX for Dummies Questions & Answers

Shell Script Unique Identifier Question

i All I have scripting question. I have a file "out.txt" which is generated by another script the file contains the following my_identifier8859574 logout The number is generated in the script and I have put the my_identifier bit in front of it as a unique identifier I now have... (7 Replies)
Discussion started by: grahambo2005
7 Replies

3. Shell Programming and Scripting

Unique Directory and Folder Deletion Script

Ok, so I just got charged with the task of deleting some 300 user folders in a FTP server to free up some space. I managed to grep and cut the list of user folders to delete into a list of one user folder per line. Example: bob00 jane01 sue03 In the home folder, there are folders a-z, and... (5 Replies)
Discussion started by: b4sher
5 Replies

4. Shell Programming and Scripting

get part of file with unique & non-unique string

I have an archive file that holds a batch of statements. I would like to be able to extract a certain statement based on the unique customer # (ie. 123456). The end for each statement is noted by "ENDSTM". I can find the line number for the beginning of the statement section with sed. ... (5 Replies)
Discussion started by: andrewsc
5 Replies

5. Shell Programming and Scripting

Unique files in a given directory

I keep all my files on a NAS device and copy files from it to usb or local storage when needed. The bad part about this is that I often have the same file on numerous places. I'd like to write a script to check if the files in a given directory exist in another. An example: say I have a... (7 Replies)
Discussion started by: cue
7 Replies

6. Shell Programming and Scripting

Change unique file names into new unique filenames

I have 84 files with the following names splitseqs.1, spliseqs.2 etc. and I want to change the .number to a unique filename. E.g. change splitseqs.1 into splitseqs.7114_1#24 and change spliseqs.2 into splitseqs.7067_2#4 So all the current file names are unique, so are the new file names.... (1 Reply)
Discussion started by: avonm
1 Replies

7. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

8. Shell Programming and Scripting

Change everything in a file that maps to {module::name.filetype} to _modules/name/applicat

path = content.txt filename = application directory = _modules define create $(eval from := $(shell echo $$1)) \ $(eval to := $(shell echo $$2)) \ sed -i '' 's/$(from)/$(to)/g' content.txt endef all: clear $(eval modules := $(shell egrep -o "{module+\}" $(path))) ... (1 Reply)
Discussion started by: bmson
1 Replies

9. UNIX for Advanced & Expert Users

File command return wrong filetype while file holds group separator char.

hi, I am trying to get the FileType using the File command. I have one file, which holds Group separator along with ASCII character. It's a Text file. But when I ran the File command the FileType is coming as "data". It should be "ASCII, Text file". Is the latest version of File... (6 Replies)
Discussion started by: Arpitak29
6 Replies

10. Shell Programming and Scripting

Bash to create new directory by date followed by identifier and additional subdirectories

I have a bash that downloads a list and if that list has data in it then a new main directory is created (with the date) with several subdirectories (example1, example2, example3). My question is in that list there are portion of specific file types (.vcf.gz) - identifier towards the end that have... (0 Replies)
Discussion started by: cmccabe
0 Replies
Tk_GetUid(3tk)						       Tk Library Procedures						    Tk_GetUid(3tk)

__________________________________________________________________________________________________________________________________________________

NAME
Tk_GetUid, Tk_Uid - convert from string to unique identifier SYNOPSIS
#include <tk.h> Tk_Uid Tk_GetUid(string) ARGUMENTS
char *string (in) String for which the corresponding unique identifier is desired. _________________________________________________________________ DESCRIPTION
Tk_GetUid returns the unique identifier corresponding to string. Unique identifiers are similar to atoms in Lisp, and are used in Tk to speed up comparisons and searches. A unique identifier (type Tk_Uid) is a string pointer and may be used anywhere that a variable of type "char *" could be used. However, there is guaranteed to be exactly one unique identifier for any given string value. If Tk_GetUid is called twice, once with string a and once with string b, and if a and b have the same string value (strcmp(a, b) == 0), then Tk_GetUid will return exactly the same Tk_Uid value for each call (Tk_GetUid(a) == Tk_GetUid(b)). This means that variables of type Tk_Uid may be com- pared directly (x == y) without having to call strcmp. In addition, the return value from Tk_GetUid will have the same string value as its argument (strcmp(Tk_GetUid(a), a) == 0). KEYWORDS
atom, unique identifier Tk Tk_GetUid(3tk)
All times are GMT -4. The time now is 02:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy