Is there a Linux terminal command for creating .xlsx files from .bracken files in a loop in a new folder - linux

Is there a loop I can use to create .xlsx files from .bracken files I currently have and channel them into an output folder?
All that I have now is to convert my .bracken files into .xlsx files using this code cat MG-ABCD12345-0.genus.bracken > MG-ABCD12345-0_genus_bracken.xlsx and files are going into my current working directory. I would like the output in a folder called bracken_excel_files which is located within my current working directory. I would prefer to use common commands such as for for the loop for easier understanding.

bracken appears to be generating/sharing the same output format as kraken, which I saw somewhere to be tab-delimited fields.
If that is true, then that is the essence of what CSV files are.
In that case, you don't need to use the "cat" command (CPU and I/O consuming). You simply need to rename the file with a ".csv" suffix (to make the file format explicitly visible for others), then import that into Excel or OpenOffice/LibreOffice Calc. Each of those tools offer different options for interpreting the input when you use the "Import" function to open the files.

Related

Batch file creation: Convert xls to csv using only batch script

I have done quite a bit of searching before posting this question so let me outline what I am trying to do.
1.) I do not want to use applications I have to download from a website or created custom commands (please no start Xls2Csv.exe here's a link to a website where you can download the program) I do not want to download a program to do this.
2.) I want to keep it in the batch file if possible - I have tried the vbc/vbs/vb files that is not what I am looking for.
3.) I found this an this is close to what I need but if I can stay within a batch file that would be best: Can a Batch File Tell a program to save a file as? (If so how)
Background
I have a bunch of test records stored in excel sheets within folders. Each test record has autoformatted name so the only real difference between any of the filenames is a serial number, otherwise each file name is formatted the exact same way.
I have written a batch file to search and find the files I need but I am stuck on obtaining a tiny bit of information in a .xls file.
What I am trying to do - I have excel files (.xls) and there is a word in a cell on one of many sheets that I would like to copy into a textfile. However I am unable to use findstr for an excel find because the command searches the file as if you opened it in notepad and the data I need is not present.
I am not concerned of data loss as long as I can get this tiny bit of information to a text file.
Otherwise what I have found to be the best solution is to convert an XLS to a CSV. I have manually done it by opening the file and saving as type .csv that worked.
What hasn't worked is:
example1.xls >> example2.csv
ren example1.xls example3.csv - this will save it as a csv file but still opens with the same formating of the xls file in both excel and notepad.
I was hoping that the was a command to recreate the manual process of opening the file and saving as csv.
If there are any other suggested solutions - maybe a command where I can search for a string within an excel file? That would be the simplest option.

Move files to their respective folder in linux based on the date of the folder and the date of the file

I'm fairly new to bash scripting and linux, and I have a folders with just dates such as
2012-11-20
2012-11-21
2012-11-22
2012-11-23
and I have files with the name data_11202012_randomnumbers_csv.
I would like to create a script that can move every single csv file to it's correct folder by matching the date on the file to the folder.
I've been just typing mv file path but i have 100s of files and I'm wondering if theres an easier way.
Any help would be appreciated.
The following should do it for you. I will explain with comments
for file in your_folder/*; do
# 1. Extract the numbers from the file name
dir="${file#data_}" # remove data_ prefix
dir="${dir%%_*}" # remove everything after first _
# 2. Rearrange the numbers into the desired format
dir="${dir:2:4}-${dir:0:2}-${dir:6:2}"
# 3. Move the file into the directory
mv file dir
done
Here you have a very useful bash cheatsheet where you can learn more about it. It illustrates all the variable expansions I've made in my snippet and more.

Adding macros script to an excel file externally in Linux

My requirement is: I have been given an excel (the user uploads it to our server) and then my program should automatically add a macros code (defined in a text file maybe) to the excel file and then send it back to the user. I found a similar question but the solution only works in Windows but since our server is Linux based, I haven't found a way to do so.
Link to the similar question: Use Python to Inject Macros into Spreadsheets
Assuming you're being sent a file in xlsm format, you need to following capabilities:
Open the file as a zip file
Locate the .bin part path from the rels files - see Microsoft Open Packaging Conventions
Locate and open the VBA project's .bin stream
parse the .bin stream as a Compound Binary File Format file
Parse the binary streams that describe and list the module contents of the file, as documented in Office VBA File Format Structure
Add your module text as a new stream, and update the files from step 5 with the new contents.
It's not a small undertaking. The work has already been done in Python, and a lot of the libraries for working with zip files and compound binary format files are already in .NET for Windows. Otherwise, as far as I'm aware, there aren't any other pre-built tools, other than the tools from aspose

Matlab: open files 'outside Matlab' by default

I'm looking for a way to have Excel files in my Matlab folder open 'outside Matlab' (i.e., by MS Excel in most cases) directly by double-clicking the file, rather than right-clicking and selecting 'Open Outside Matlab'.
The .xls files reader built in Matlab can be terribly slow for large files, and an unwanted double-click on a file can cost quite some time in which Matlab is unresponsive.
Thanks.
When you click something in the Current Folder tab, it's actually running the open command, which itself calls finfo to determine what it means by "open" for a given extension. You can see this by creating a breakpoint in open.m directly after the line [~, openAction] = finfo(fullpath); and double clicking - when it hits the breakpoint you'll see it returns openAction as uiimport.
In theory, you can create custom methods for extensions by creating on the path a function openabc where abc is the extension, which should be returned as the openAction.
However, if I look at my finfo.m it first searches for said functions and then regardless of whether or not it finds them if there is an inbuilt method it overwrites them with the standard behaviour. There's even a comment:
% this setup will not allow users to override the default EXTread behavior
If you are willing to muck about in the inbuilts, you may be able to do it like this (backup first! - this could affect other things). I did it temporarily by shadowing the existing finfo like this:
edit finfo.m (Now save a copy to the current folder)
Add these lines after the loop that defines the openAction (in my version, around line 85):
if any(strcmp(['.' ext], matlab.io.internal.xlsreadSupportedExtensions))
openAction = 'winopen';
end
From the folder containing your edited finfo.m, type which finfo -all. You should see two copies, the MATLAB one labelled as shadowed. Opening something from the current folder window should now open Excel externally.
I don't believe there's any straightforward way to do that. It's built in to MATLAB that Excel files will open in the import tool when you double click on them, and there's no way to change that.
You might be able to get around it by changing the file extension on your Excel files to something other than .xls or .xlsx. That would stop MATLAB from opening it in the import tool. Then in Windows, you could associate the new file extension with Excel.

mass convert Excel files into tab-delimited text files

Is there a tool to convert a large number of excel files into tab delimted files automatically?
I just through this together, its not pretty but should do what you need. Tested on WindowsXP / Office2007.
download from: http://stembro.byethost17.com/utility_scripts/xl2tab/xl2tab.html
Extract the xl2tab.vbs file to the directory containing the excel files and double-click to run. It will place the converted files into a new directory called "output." The original directory-structure remains intact within the output folder.
I don't think there are any good free tools to do so right now, but you could look into using the Open Office API to write something,
[http://www.oooforum.org/forum/viewtopic.phtml?t=7657&highlight=convert+xls+csv+command+line][1]
Or for a quick and dirty solution, you could record and Open Office Calc macro that would do it, and launch that macro from the command line.
This might also help http://dag.wieers.com/home-made/unoconv/
convert to csv, and maybe replace , with tabs?

Resources