Sponsored Content
Top Forums Shell Programming and Scripting Rename file using partial match to another Post 303040185 by MadeInGermany on Thursday 24th of October 2019 02:42:14 PM
Old 10-24-2019
It looks a bit complicated.
Perhaps you want to do the following?
Code:
dir=/path/to/run
ind=0
while read a b c
do
  if [ -n "$b" ]
  then
    fsearch[ind]=$a
    mvto[ind]=$b
    ((ind++))
  elif [ -z "$a" ]
  then
    ind=0
  else
    while [ $ind -gt 0 ]
    do
      ((ind--))
      echo "In $dir/$a/data/ rename ${fsearch[ind]}*.bam* to ${mvto[ind]}_test.bam*" 
    done
  fi
done < $dir/f1

This User Gave Thanks to MadeInGermany For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk partial match and filter records

Hi, I am having file which contains around 15 columns, i need to fetch column 3,12,14 based on the condition that column 3 starts with 40464 this is the sample data how to achieve that (3 Replies)
Discussion started by: aemunathan
3 Replies

2. Shell Programming and Scripting

Using grep returns partial matches, I need to get an exact match or nothing

I’m trying to modify someone perl script to fix a bug. The piece of code checks that the zone name you want to add is unique. However, when the code runs, it finds a partial match using grep, and decides it already exists, so the “create” command exits. $cstatus = `${ZADM} list -vic | grep... (3 Replies)
Discussion started by: TKD
3 Replies

3. UNIX for Dummies Questions & Answers

Partial match in two files then substitute

Hi, I was trying to figure this out but failed so I hope someone here can help me, thank you in advance. I have two files. file1: aa M bb N cc O dd P ee Q file2: aa A_87_P254063 cc A_87_P016532 bb A_87_P104793 dd A_87_P055331 ee A_87_P059706 aa A_87_P071636 ee A_87_P028302... (2 Replies)
Discussion started by: yuejian
2 Replies

4. UNIX for Dummies Questions & Answers

How to substitute for the partial match?

Hi I have a question and hope I can get answer here. Thank you in advance. I have two files: file1: aa X bb Y cc Z file2: cc A bb B dd C aa D bb E If the 1st column match in both file1 and file2, the 2nd column in file2 will be replaced by the 2nd column in file1. If there is no... (2 Replies)
Discussion started by: yuejian
2 Replies

5. Shell Programming and Scripting

Match partial text

I posted the incorrect files yesterday and apologize. I also modified the awk script but with no luck. There are two text files in the zip (name.txt and output.txt). I am trying to match $2 in name.txt with $1 in output.txt and if they match then $1 of name.txt is copied to $7 of output.txt. ... (7 Replies)
Discussion started by: cmccabe
7 Replies

6. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

7. Shell Programming and Scripting

Rename files to match file list pattern

Hi All, I have 100 folders with the first delimiter has a unique name i.e (123_hello and 575_hello) and each folder have atlist 1000 plus files with naming convention i.e (575_hello_1.iso ... 575_hello_1000.iso). 575_hello/575_hello_1.iso 575_hello/575_hello_2.iso 575_hello/575_hello_3.iso... (8 Replies)
Discussion started by: lxdorney
8 Replies

8. Shell Programming and Scripting

Partial Match and Replace

Hi, I have a tab delimited text file like this one. I need to do a partial match of a particular cell and then replace matches with an empty cell. So here is a sample: Smith FordMustang ChevroletCamaro Miller FordFiesta Jones KiaSorrento Davis ChevroletCamaro Johnson ToyotaHighlander I... (4 Replies)
Discussion started by: mikey11415
4 Replies

9. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

10. Shell Programming and Scripting

Bash to rename portion of file using match to another

In the portion of bash below I am using rename to match the $id variable to $file and when a match (there will alwsys be one) is found then the $id is removed from each bam and bam.bai in $file and _test is added to thee file name before the extension. Each of the variables is set correctly but... (3 Replies)
Discussion started by: cmccabe
3 Replies
DS(3)                                                      DACS Library Functions Manual                                                     DS(3)

NAME
ds - Dynamic strings and vectors SYNOPSIS
#include "dsslib.h" Ds *ds_init(Ds *ods); Ds *ds_init_size(Ds *ods, size_t nbytes); Ds *ds_alloc(void); Ds *ds_alloc_size(size_t nbytes); Ds *ds_reinit(Ds *ds); Ds *ds_reinit_size(Ds *ods, size_t nbytes); Ds *ds_reset(Ds *ds); Ds *ds_reset_buf(Ds *ds); Ds *ds_trim(Ds *ds); Ds *ds_grow(Ds *ds); void ds_free(Ds *ds); int ds_appendc(Ds *ds, int ch); int ds_copyb(Ds *ds, void *src, size_t len, unsigned int offset); int ds_insertb(Ds *ds, void *src, size_t len, unsigned int offset); int ds_append(Ds *ds, char *str); int ds_concat(Ds *ds, char *str); int ds_concatc(Ds *ds, int ch); int ds_concatn(Ds *ds, char *str, size_t len); Ds *ds_set(Ds *ds, char *str); Ds *ds_setn(Ds *ds, unsigned char *s, size_t slen); Ds *ds_range(Ds *ds, char *str, char *range_spec, Range_syntax *ors); int ds_getc(Ds *ds, FILE *fp, int *ch_ptr); Dsio *dsio_set(Ds *ds, FILE *fp, char *buf, unsigned long len, int have_length); int dsio_free(Ds *ds); int dsio_eof(Ds *ds); int dsio_nextc(Ds *ds, int *ch_ptr); int dsio_peekc(Ds *ds, int *ch_ptr); char *dsio_agets(Ds *ds); char *dsio_gets(Ds *ds); int dsio_load(Ds *ds); char *dsio_load_str(Ds *ds); char *ds_gets(Ds *ds, FILE *fp); char *ds_agets(Ds *ds, FILE *fp); char *ds_agets_buf(Ds *ds, char *buf); char *ds_prompt(Ds *ds, char *prompt, unsigned int flag); char *ds_readline(Ds *ds, char *prompt, char *cprompt); Ds *ds_load_file(Ds *ds, char *pathname); Ds *ds_agetf(Ds *ds, FILE *fp); Ds *ds_getf(FILE *fp); int ds_sprintf(Ds *ds, unsigned int offset, char *fmt, ...); int ds_asprintf(Ds *ds, char *fmt, ...); int ds_vasprintf(Ds *ds, char *fmt, va_list ap); char *ds_xprintf(char *fmt, ...); char *ds_vxprintf(char *fmt, va_list ap); FILE *ds_fopen_secure(const char *path, const char *mode, size_t size); int ds_fclose(FILE *fp); int ds_fclean(FILE *fp); Dsvec *dsvec_init(Dsvec *dsv, size_t size); Dsvec *dsvec_alloc(size_t size); Dsvec *dsvec_init_size(Dsvec *dsv, size_t size, int n); Dsvec *dsvec_alloc_size(size_t size, int n); void dsvec_free(Dsvec *dsv); Dsvec *dsvec_grow(Dsvec *dsv, unsigned int new_nelements); Dsvec *dsvec_subset(Dsvec *dsv, Dsvec *old_dsv, unsigned int start, int len); Dsvec *dsvec_copy(Dsvec *dsv, Dsvec *old_dsv); void *dsvec_ptr_index(Dsvec *dsv, unsigned int ind); int dsvec_delete_ptr_index(Dsvec *dsv, unsigned int ind); int dsvec_delete_ptr(Dsvec *dsv, void *ptr); int dsvec_replace_ptr(Dsvec *dsv, void *ptr, unsigned int ind); int dsvec_streq(Dsvec *dsv1, Dsvec *dsv2); int dsvec_strneq(Dsvec *dsv1, Dsvec *dsv2, size_t len); int dsvec_rotate(Dsvec *dsv, int npos); Dsvec *dsvec_strlist(Dsvec *dsv, char *str_spec); Dsvec *dsvec_slice(Dsvec *dsv, Dsvec *primary, unsigned int ind, unsigned int len); Dsvec *dsvec_range(Dsvec *dsv, Dsvec *primary, char *range_spec, Range_syntax *ors); int dsvec_replace(Dsvec *primary, unsigned int ind, unsigned int delete_len, Dsvec *secondary); int dsvec_append(Dsvec *primary, Dsvec *secondary); int dsvec_insert_ptr(Dsvec *dsv, unsigned int ind, void *ptr); int dsvec_add_ptr(Dsvec *dsv, void *ptr); int dsvec_insert(Dsvec *primary, unsigned int ind, Dsvec *secondary); int dsvec_delete(Dsvec *dsv, unsigned int ind, unsigned int ndelete); int dsvec_add_obj(Dsvec *dsv); void dsvec_sort(Dsvec *dsv, int (*compar)(const void *, const void *)); Dsvec *dsvec_load(Ds *ds, Dsvec *dsv); Dsvec *ds_mkargv_add(Dsvec *dsv, char *el); Dsvec *ds_mkargv_addv(Dsvec *dsv, int argc, char **argv); typedef struct Mkargv { int keepq; int keepws; char *ifs; char *startq; char *endq; } Mkargv; Dsvec *ds_mkargv(Dsvec *dsv, char *str, Mkargv *conf); char *ds_buf(Ds *ds); size_t ds_len(Ds *ds); size_t ds_size(Ds *ds); int ds_eq(Ds *ds1, Ds *ds2); (TYPE) dsvec_ptr(Ds *DSV, unsigned int IND, TYPE); (TYPE) dsvec_obj(Ds *DSV, unsigned int IND, TYPE); (TYPE) dsvec_new_obj(Ds *DSV, TYPE); (TYPE) dsvec_base_type(Ds *DSV, TYPE); void **dsvec_base(Dsvec *dsv); unsigned int dsvec_len(Dsvec *dsv); extern int ds_default_clear_flag; extern int ds_default_delnl_flag; extern size_t ds_default_len_limit; extern void *(*ds_default_malloc_func)(size_t size); extern void *(*ds_default_free_func)(void *ptr); DESCRIPTION
The DS library is a collection of functions for creating, manipulating, and formatting strings of bytes. The memory used by these strings is dynamically allocated and released as necessary. When used correctly, bugs caused by buffer overruns and other programming errors can be avoided. There are also functions for creating and manipulating dynamic vectors of pointers and objects. Byte Strings A Ds data structure represents a dynamic string. It must be initialized before it can be used. A Ds variable contains several fields that may be set after initialization but before it is first used. Default values for some of these fields are copied from global variables exported by the library. Initialization Manipulation Formatting Vectors DACS 1.4.27b 10/22/2012 DS(3)
All times are GMT -4. The time now is 03:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy