How to rename multiple file extensions at the same time? - linux

I already referred this post and post
I have my filenames like as shown below (1 set contains 3 related files). In my directory, I have 40 set of files (meaning 120 files). All the 40 sets have 3 files with same file extension
Set 1
Test_t5.version9.info.gz
Test_t5.version9.dose.vcf.gz.tbi
Test_t5.version9.dose.vcf.gz
Set 2
Test_t5.version12.info.gz
Test_t5.version12.dose.vcf.gz.tbi
Test_t5.version12.dose.vcf.gz
Only the version number in file changes across different sets.
Now, I would like to rename my files like as shown below
Set 1
Test_t5.version9.info.gz
Test_t5.version9.dose.vcf.gz.tbi
Test_t5.version9.dose.vcf.bgz #see the change here from `.gz to .bgz`
Set 2
Test_t5.version12.info.gz
Test_t5.version12.dose.vcf.gz.tbi
Test_t5.version12.dose.vcf.bgz #see the change here from `.gz to .bgz`
I tried the below but guess am making mistake while executing the command in the shell.
rename 's/dose.vcf.gz/dose.vcf.bgz/' Test_t5.version*.dose.vcf.gz
Basically modify the file extension for only one file in each of the set. You don't have to worry about Set 1 or Set 2. That was for you to understand that how our data is grouped.
Can you help please?

It looks like you are just wanting to do:
for file in *.vcf.gz; do mv "$file" "${file%.gz}.bgz"; done

Related

Copy a set of files using ADF

I have 10 files in a folder and want to move 4 of them in a different location.
I tried 2 approaches to achieve this -
using lookup to retrieve the filenames from a json file- then feeding it to a for each iterator
using metadata to get file names from source folder and then adding if condition inside a for each to copy the files.
But in both the cases, all the files in source folder gets copied.
Any help would be appreciated.
Thanks!!
There a 3 ways you can consider selecting your files depending on the requirement or blockers.
Checkout official MS doc: Copy activity properties
1. Dynamic content for FilePath property in Source Dataset.
2. You can use Wildcard character in the source folder and file path in the source Dataset.
Allowed wildcards are: * (matches zero or more characters) and ?
(matches zero or single character); use ^ to escape if your actual
folder name has wildcard or this escape char inside. See more
examples in Folder and file filter
examples.
3. List of Files
Point to a text file that includes a list of files you want to copy,
one file per line, which is the relative path to the path configured
in the dataset. When using this option, do not specify file name in
dataset. See more examples in File list
examples.
Example:
Parameterize source dataset and set source file name to that which passes the expression evaluation in IfCondition Activity.

Copying and pasting using Python for files with similar but not exact names

I have two folders each with several files.
Folder 1:
abc_1600_efg.xlsx
abc_1601_efg.xlsx
abc_1602_efg.xlsx
abc_1603_efg.xlsx
Folder 2:
ijk_1600_xyz.xlsx
ijk_1601_xyz.xlsx
ijk_1602_xyz.xlsx
ijk_1603_xyz.xlsx
lmn_1600_tuv.xlsx
lmn_1601_tuv.xlsx
lmn_1602_tuv.xlsx
lmn_1603_tuv.xlsx
Assuming the files in each folder are randomized, anyone have any ideas on how to use python 3.x to copy from file 'abc_1600_efg.xlsx' in folder 1 then have python search for the corresponding file in folder 2 ('ijk_1600_xyz.xlsx'). The number portion of the title is the key that needs to be matched. Then I want to paste the data into the file 'ijk_1600_xyz.xlsx' (folder two has two files with the same number 1600 but I need to find just the 'ijk_1600_xyz' file).
I want to loop this so that this would be done for every file in folder 1 starting at 1600 then 1601 then 1602 etc. I have the copy and paste portion finished I'm just stuck on the search and match portion.
Thank you in advance.
I haven't checked it
but something like:
import re,os
for file1 in os.listdir(folder1):
match=re.match('..._(\d+)_.*'),file1).group(1)
for file2 in os.listdir(folder2):
if ('_'+match+'_' in file2) :
... copy ...
Anyway, you should know how to adapt to these situations.

Searching in multiple files using findstr, only proceeding with the resulting files? (cmd)

I'm currently working on a project where I search hundreds of files using findstr in the command line. If I find the string which I searched for, I want to proceed with this exact file (and the other ones that include my string).
So in my case:
I searched for the string WRI2016 by using:
H:\KOBINI>findstr "WRI2016" *.ini > %temp%\xx.txt && %temp%\xx.txt
To see what the PC does, I save it in a .txt file as you can see.
So if my file includes WRI2016 I want to extract some facts out of the file. In my case it is NR, Kunde, WebHDAktiv, DigIDAktiv.
But I just can't find a proper way to link both of these functions.
At first I simply printed all of the parameters:
H:\KOBINI>findstr "\<NR Kunde WRI2016 WebHDAktiv DigIDAktiv" *.ini > %temp%\xx.csv && %temp%\xx.csv
I also played around using the if command but that didn't really work out. I'm pretty new to this stuff as you'll see in my following tries to solve this problem:
H:\KOBINI>findstr "\<NR DigIDAktiv WebHDAktiv" set a =*.ini findstr "WRI2016" set b =*.ini if a EQU b > %temp%\xx.txt && %temp%\xx.txt
So all I wanted to achieve with that weird code was: if there is a WRI2016 in the file, give me the remaining parameters. But that didn't work out at all.
I also tried it with using new lines for every command which didn't change a thing.
As I want this to be a .csv in the end I want to add a semicolon between my parameters, any chance how I could do that? I've seen versions using -s";" which didn't do anything for me.
Sorry, I'm quite new and thought I'd give it a shot.
an example of my .ini files Looks like this:
> Kunde=Markt
> Nr=101381
> [...]
> DigIDAktiv=Ja
> WebHDAktiv=Nein
> Version=WRI2016_U2_P1
some files have a different Version though.
So I only want to know "NR, DigIDAktiv ..." if it's the 2016 Version.
As a result it should be sorted in a CSV, in different columns.
My Folder Looks like this
So I search These files in order to find Version 2016 and then try to extract my Information and put it into a .csv

Copy files with new sequential name (Linux)

I have this file named checkinout100.php and need to copy it to another 100 files following the numbered sequence like checkinout101.php, checkinout102.php and so on until 200.
I've been looking to do it with seq but can't figure it out on my own.
Thanks.
NOTE: Has nothing to do with webpages. It's an Asterisk PBX (Yeastar), I need one of those files per extension (link with hotel software).
You can use seq in the following way:
for n in $(seq 101 200) ; do
cp checkinout100.php checkinout$n.php
done

writing data from a program to a file

I'm using linux. Let's say I have a program named add. The program takes two numbers.
so if I type in
add 1 2
the answer is 3 //obvious
what command will make this write out to a file named add.data
I'm kind of a linux n00b. I was reading about piping. Thanks.
Piping means sending the output of a program as input to a second, which must be able to read data from the standard input, e.g.
add 1 2 | echo
What you are asking about here is output redirection: you should use
add 1 2 > add.data
to create a new file with your output (if existing will be overwritten), and
add 1 2 >> add.data
to create a new one or append to an existing.
add 2 3 > something.txt
This will redirect output into a file, recreates the file every time
add 1 2 > add.data
This will append to the end of the file
add 1 2 >> add.data

Resources