How to generate multiple files in sequence with data in sequence? - file

I have to create 50 files in sequence labelled r01.inp to r50.inp and in each file I need this text in sequence as well.
#!/bin/bash
abc2 r01.inp > r01.log
I am trying to generate multiple files and the data inside it to also be in a sequence i.e. file r01.inp has "abc2 r01.inp > r01.log" while the next file r02.inp has "abc2 r02.inp > r02.log" in it and so on.
I know that by using echo and touch I can create the 50 files but all of them has same data and I still have to manually change "r01.inp > r01.log" in each of the files to match the file name.
I am expecting a single script which would generate multiple files with each file having their own respective data.

Related

Concatenate 2 files from a list based on partial matching

I have a list of files that need to be concatenated (or appended). I know how to do it one by one but I'm not sure how to loop through them. Bonus points for using Parallel to run them simultaneously.
For the result manually, I would run:
cat exp-2-2_S1_L001_R1_001.fastq >> Exp-2-2_reseq_S1_L001_R1_001.fastq
But there are hundreds of files. Also, can this be done on compressed files with zcat?
Example of some of the files that need to be concatenated or appended (in order):
with
Thanks in advance!!!

Using cmd to move files with a specific filename mask

I am trying to use a simple windows cmd command to move a set of .csv files from one directory to another.
I know that this can be easily achieved through:
MOVE "*.csv" "D:/lorik_home"
The issue comes when I want to only move some specific files with a filename mask, for instance, I want to move all files which are in the .csv extension and start with the name: lorik_files_. I already tried using:
MOVE "lorik_files_*.csv" "D:/lorik_home"
This works when there is only one file of the format: lorik_files_20112233_09_33_33.csv, but when there are two files with the masks such as:
lorik_files_20112233_09_33_33.csv
lorik_files_20112233_10_23_42.csv
I get an error such as:
A duplicate file name exists, or the file cannot be found.
I need a hand for capturing those filename prefix masks, conditioned by .csv extension at the end.

How do I check for a world in multiple txt files at once?

I have a huge data set of around 120gbs that contains several txt files of each 2-3 gb+ sizes. I want to look for a string inside all those files at once.
I tried notepad++ find by folder option but it doesn't allow me to open large txt files.

How to replace text from a source file into different files

So I have been using Notepad++ to do some little clean-up tasks and now I am left with the biggest task..
I have a file called Artists.txt which looks like
Butta Mohamed
Daler Mehndi
Daljit Mattu
Darshan Khela
Davinder Deep
Davinder Deol
etc...
I have another file called Keywords.txt (located in hundreds of other folders). The folders are named like below and they all contain a text file called Keywords.txt
butta-mohamed-lyrics
daler-mehndi-lyrics
daljit-mattu-lyrics
darshan-khela-lyrics
davinder-deep-lyrics
davinder-deol-lyrics
The Keywords.txt contains the text _1 (several instances within the Keywords.txt).
What I would like to do is get each line from Artists.txt and have the _1 replaced. The folders are in the same order as Artists.txt.
So read Artists.txt get first line Butta Mohamed get first folder butta-mohamed-lyrics edit Keywords.txt find _1 replace (all) with Butta Mohamed. Save changes. Rinse and repeat so read Artists.txt get next line Daler Mehndi get next folder daler-mehndi-lyrics edit Keywords.txt find _1 replace (all) with Daler Mehndi. Save Changes.
Wondering if something like this is possible? Otherwise it would take me a week to manually do this via copy/pasting or even the replace function in Notepad++
I've tried the Macro function in Notepad++ but CTRL-V rather then pasting whats in the clipboard the macro seems to replace the CTRL-V function with whatever text the macro was recorded with has.
So just adding some extra information...
I don't have Notepad++ installed as my favorite text editor is UltraEdit (shareware).
Although Stack Overflow is not a free code writing service and we expect that the questioner shows us some programming efforts already made to solve a task, it was very easy for me to write the little UltraEdit script for this task and therefore here is an UltraEdit script for this task.
C:\\Temp\\Test\\ at top of the script must be replaced by path of parent folder for the *lyrics folders. UltraEdit scripts are executed with the JavaScript core engine. Strings in UltraEdit scripts are therefore JavaScript strings where backslash is the escape character. So it is necessary to escape each backslash in parent folder path by one more backslash.
To run this script in UltraEdit, open Artists.txt as first file in UltraEdit.
As second file create a new ASCII file with Ctrl+N, copy and paste the lines below into this new file, edit the parent folder path/name in script code and save this script for example with name KeywordsReplace.js into any folder.
Now run the script by clicking in menu Scripting on command Run Active Script.
You can see after script finished in automatically showed output window how many replaces have been made in which Keywords.txt files.
if (UltraEdit.document.length > 0) // Is any file opened?
{
// Parent folder containing all the *lyrics folders.
var sParentFolder = "C:\\Temp\\Test\\";
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
// Select everything in first file.
UltraEdit.document[0].selectAll();
// Is first file not an empty file?
if (UltraEdit.document[0].isSel())
{
// Determine line terminator type for first file.
var sLineTerm = "\r\n";
if (UltraEdit.document[0].lineTerminator == 1) sLineTerm = "\n"
else if (UltraEdit.document[0].lineTerminator == 2) sLineTerm = "\r"
// Get all lines of first file into an array of strings
var asArtists = UltraEdit.document[0].selection.split(sLineTerm);
// Remove last string if it is empty because file ended with
// a line termination.
if (!asArtists[asArtists.length-1].length) asArtists.pop();
// Define once the parameters for all the replace in files executed
// below in the loop with changing directory and replace strings.
UltraEdit.frInFiles.filesToSearch=0;
UltraEdit.frInFiles.searchSubs=false;
UltraEdit.frInFiles.ignoreHiddenSubs=false;
UltraEdit.frInFiles.openMatchingFiles=false;
UltraEdit.frInFiles.searchInFilesTypes="Keywords.txt";
UltraEdit.frInFiles.regExp=false;
UltraEdit.frInFiles.matchCase=true;
UltraEdit.frInFiles.matchWord=false;
UltraEdit.frInFiles.logChanges=true;
UltraEdit.frInFiles.useEncoding=false;
UltraEdit.frInFiles.preserveCase=false;
// Run for each artist a replace of all occurrences of _1
// in the artists lyrics folder by name of the artist.
for (nArtist = 0; nArtist < asArtists.length; nArtist++)
{
// Build folder name by converting artists name to
// lower case and replacing all spaces by hyphens.
var sFolder = asArtists[nArtist].toLowerCase().replace(/ /g,"-");
// Define directory for replace in files by appending
// additionally the string "-lyrics" to folder name.
UltraEdit.frInFiles.directoryStart = sParentFolder + sFolder + "-lyrics\\";
UltraEdit.frInFiles.replace("_1",asArtists[nArtist]);
}
// The output window contains the summary information
// about the replaces made and therefore open it.
UltraEdit.outputWindow.showWindow(true);
}
}
Script was tested with the provided data with each Keywords.txt containing exactly 3 times _1 in the 6 *lyrics folders. Result of output window was:
Running script: C:\Temp\KeywordsReplace.js
============================================================
C:\Temp\Test\butta-mohamed-lyrics\Keywords.txt, 3
3 items replaced in 1 files.
C:\Temp\Test\daler-mehndi-lyrics\Keywords.txt, 3
3 items replaced in 1 files.
C:\Temp\Test\daljit-mattu-lyrics\Keywords.txt, 3
3 items replaced in 1 files.
C:\Temp\Test\darshan-khela-lyrics\Keywords.txt, 3
3 items replaced in 1 files.
C:\Temp\Test\davinder-deep-lyrics\Keywords.txt, 3
3 items replaced in 1 files.
C:\Temp\Test\davinder-deol-lyrics\Keywords.txt, 3
3 items replaced in 1 files.
Script succeeded.
In case of downloading and installing UltraEdit is not acceptable for you, you have to wait for another answer providing a batch file solution or a Notepad++ macro solution, or you make the necessary code writing by yourself.

Batch File task in windows - Find and replace across multiple files

I have to write a batch file which finds and replaces values of version and build with their new values given by the user as an input.
The user initially gives 3 values: Apps, version and build values (the new values).
The search is then made across multiple .property files in a folder. The Apps value is searched across multiple files and wherever there is a match, the version and build of that file will be replaced by the values given by the user.
To Find and replace across multiple files easily, use FART!

Resources