Modify text file in VMDK - bash

I need to modify a text file in the file system of a VMDK file for a deployable OVA file. I have seen that it is possible to find the string (a test string in the text file needing modification) and replace it in the VMDK using sed, however whenever I try to replace it, it seems to work, but then nothing actually changes in the file. Here is what I have tried:
sed -i 's/oldstring/newstring/g' file.vmdk
The sha1sum before and after are identical telling me the file has not been modified. Something gets goofed up though because I can no longer start the VM of that VMDK (its ok, its a test).
Does anyone have any programmatic suggestions here. I will be doing all of this in bash. If no one can suggest anything, I will move this question to servar fault or SuperUser and ask if anyone knows how to mount the VMDK (Without VMware-tools!!!) then edit the file directly with sed or via some other means.
Perhaps there is some way of doing a binary search or something for the string to replace.

Related

Building useable program in Terminal/Applescript for extracting XLSX to CSV

I'm looking for a way to automate XLSX to CSV conversion. Ideally, I would also like to add column names that are not yet in the XLSX.
For now, I'm using CSVkit/In2CSV. This works, but I still have to enter the name of the file manually. In terminal, I now do this:
in2csv /Users/file.xslx -f xlsx -I > file.csv
I would like to be able to automate this, so that when I open the script, it asks me for the location of the file (or I just drag the file to the script), and then it automatically converts. I have looked into AppleScript, but can't really seem to figure it out, must probably be very easy. How can I automate this? I'm on a Mac.

Deleting a File or Replacing a File when Outsheeting in Stata

I open up a .txt file. Make some modifications to it. Then I'd like to outsheet it with the same name. To do this, I presume either I'd have to delete the file right before I outsheet it or replace the file in the outsheeting process. As a backup, I can manually delete the .txt execute the relevant code.
I'd like to do this via Stata, however. Is it possible to either:
1. Delete a .txt file within a Stata .doe--say with a shell command ?
2. Overwrite a .txt file in the outsheeting process ?
I am outsheeting as in:
outsheet v1 v2 using "file.txt", nolabel delim(",")
I run Stata in Windows on an XP machine.
Add the replace option anywhere after the comma.
You can can also shell out to the OS. Type "h shell" to see how.
Or just use rm/erase directly.

Using sed to find a string in one file and replace with text in another file in Xcode

shell: /bin/tcsh
I'm attempting to search for a string in a Cocos2D tmx file and replace it with text from another file.
Before the touch commands in Run Script, I have the following:
sed -i '' 's{<tileset firstgid="1.*<layer name="background"{Resources/maps_sideScrolling/tileProperties.txt{g' Resources/maps_sideScrolling/ruinsItemCave2.tmx;
I'm fairly certain the file ruinsItemCave2.tmx is found, because if I change the file path I get an error when I build the project. As of now, ruinsItemCave2.tmx is not affected in any way.
Eventually I will want to change ruinsItemCave2 to a wildcard filename so it affects every file name, though I'm not sure how to write Resources/maps_sideScrolling/*.tmx the proper way.
I also know that without even writing a file path of tileProperties.txt, but just writing "test" does nothing to my ruinsItemCave2 file, so I can't even get that far as of now. Does it have to do with using tcsh?

saving entire file in VIM

I have a very large CSV file, over 2.5GB, that, when importing into SQL Server 2005, gives an error message "Column delimiter not found" on a specific line (82,449).
The issue is with double quotes within the text for that column, in this instance, it's a note field that someone wrote "Transferred money to ""MIKE"", Thnks".
Because the file is so large, I can't open it up in Notepad++ and make the change, which brought me to find VIM.
I am very new to VIM and I reviewed the tutorial document which taught me how to change the file using 82,449 G to find the line, l over to the spot, x the double quotes.
When I save the file using :saveas c:\Test VIM\Test.csv, it seems to be a portion of the file. The original file is 2.6GB and the new saved one is 1.1GB. The original file has 9,389,222 rows and the new saved one has 3,751,878. I tried using the G command to get to the bottom of the file before saving, which increased the size quite a bit, but still didn't save the whole file; Before using G, the file was only 230 MB.
Any ideas as to why I'm not saving the entire file?
You really need to use a "stream editor", something similar to sed on Linux, that lets you pipe your text through it, without trying to keep the entire file in memory. In sed I'd do something like:
sed 's/""MIKE""/"MIKE"/' < source_file_to_read > cleaned_file_to_write
There is a sed for Windows.
As a second choice, you could use a programming language like Perl, Python or Ruby, to process the text line by line from a file, writing as it searches for the doubled-quotes, then changing the line in question, and continuing to write until the file has been completely processed.
VIM might be able to load the file, if your machine has enough free RAM, but it'll be a slow process. If it does, you can search from direct mode using:
:/""MIKE""/
and manually remove a doubled-quote, or have VIM make the change automatically using:
:%s/""MIKE""/"MIKE"/g
In either case, write, then close, the file using:
:wq
In VIM, direct mode is the normal state of the editor, and you can get to it using your ESC key.
You can also split the file into smaller more manageable chunks, and then combine it back. Here's a script in bash that can split the file into equal parts:
#!/bin/bash
fspec=the_big_file.csv
num_files=10 # how many mini-files you want
total_lines=$(cat ${fspec} | wc -l)
((lines_per_file = (total_lines+num_files-1) / num_files))
split --lines=${lines_per_file} ${fspec} part.
echo "Total Lines = ${total_lines}"
echo "Lines per file = ${lines_per_file}"
wc -l part.*
I just tested it on a 1GB file with 61151570 lines, and each resulting file was almost 100 MB
Edit:
I just realized you are on Windows, so the above may not apply. You can use a utility like simple text splitter a Windows program which does the same thing.
When you're able to open the file without errors like E342: Out of memory!, you should be able to save the complete file, too. There should at least be an error on :w, a partial save without error is a severe loss of data, and should be reported as a bug, either on the vim_dev mailing list or at http://code.google.com/p/vim/issues/list
Which exact version of Vim are you using? Using GVIM 7.3.600 (32-bit) on Windows 7/x64, I wasn't able to open a 1.9 GB file without out of memory. I was able to successfully open, edit, and save (fully!) a 3.9 GB file with the 64-bit version 7.3.000 from here. If you're not using that native 64-bit version yet, give it a try.

read directory file

we all know that in linux directory is a special file containing the file name and the inode number of constituent files. I want to read the contents of this directory file using standard command line utility.
cat . gives an error that I cannot open a directory.
However, apparently vim can understand the content of this file using readdir probably. It displays the contents of the directory file in a formatted manner. I want the raw contents of the file. How is this possible ??
As far as I can tell, it cannot be done. I was pretty sure dd would do it, and then I found the following
‘directory’
Fail unless the file is a directory. Most operating systems do not allow I/O to a directory, so this flag has limited utility.
http://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html
So I think you have your answer there. dd supports it, as do probably a number of other utilities, but that doesn't mean linux allows it.
I think stat might be the command you're looking for.

Resources