How to define file type using c1541 -write command (VICE) - emulation

I'm trying to copy foo.txt file to disk.64 image using c1541 utility.
I've tried to write:
c1541 disk.d64 -write foo.txt foo
The file is copied but as foo.prg
How can save it using SEQ or USR types? I've tried:
c1541 disk.d64 -write foo.txt foo.seq
only to find that the file is copied as foo.seq.prg.

Try c1541 disk.d64 -write foo.txt "foo,s" for SEQ-files and c1541 disk.d64 -write foo.txt "foo,u" for USR-files.

Related

How to clean ctrl+z in linux file?

I have copied some text files from windows to redhat machine using putty. When i try to execute the files . I am getting error because ctrl+z was added in that file.
I have used this command
tr -d '\15\32' < /path/gems/spec/rms.spec > /path/gems/spec/rms.spec
But the above command is annoying because I have 1000+ .spec files under various folder.
Is there any option in linux command to identify the .spec files in the directory and clean the ctrl+z added in the file.
Thanks in advance
If you are using bash, you can try with:
find . -type f -name '*.spec' -print0 | \
while IFS= read -r -d '' dot_spec_file; do \
cat "$dot_spec_file" | \
tr -d '\15\32' | \
sponge "$dot_spec_file" \
; done
Execute it on the parent directory of your .spec files.
sponge reads all its input before write the file; from its manual:
sponge reads standard input and writes it out to the specified file.
Unlike a shell redirect, sponge soaks up all its input before opening
the output file. This allows constructing pipelines that read from and
write to the same file.

how to find file in jar without unjarring it and opening in editor from command line?

I have a foo.jar which has classes, a lib directory and a META-INT directory.
I am trying to find if persistence.xml exists in this jar and open it in vi editor.
I tried the following.
tar tf foo.jar | grep 'persistence.xml'
This shows META-INF/persistence.xml.
I am wondering if it is possible to first find the file in jar and then open in vi in single command line if possible.
It's not actually the single command but in one line you can do it as follows:
jar=foo.jar; filename=$(unzip -l "$jar" | grep 'persistence.xml' | awk '{print $4}'); test -n "$filename" && vim <(unzip -qc "$jar" "$filename")
First you have to set jar file that you will be evaluated and then command is looking for the file name that matches the pattern. Finally if file name is non zero length string, file is being opened in vim editor.

Using grep to overwrite its current file

I have a list of directories within directories and this is what I am trying to attempt:
find a specific file format which is .xml
within all these .xml files, read the contents in the files and remove line 3
For line 3, its string is as follows: dxflib <Name of whatever folder it is in>.dxb
I tried using find -name "*.xml" | xargs grep -v "dxflib" in the terminal (I am using linux) and I found out that while my code works and it displays the results, it did not overwrite the changes to the file.
And as I googled online, it is mentioned that I will need to add in >> output.txt etc
And hence, are there anyways in which I can make it to save / overwrite its own file?
Removes third line in file:
sed -i '3d' file

Command to open a file which contains the given data

I had this question in interview.
He put a situation in front of me that there are 12 files in your Linux operating system.
Give me a command which will open a file containing data "Hello"..
I told him I just know grep command which will give you the names of files having "Hello" data.
Please tell me if there is any command to open a file in this way..
Assuming it will be only one file containing the word hello:
less $(grep -H "hello" *.txt | sed s/:.*//)
Here it is first capturing the file name using grep with -H parameter. Then using sed removing everything except the filename. And finally its using less to open the file.
Maybe this could help:
$ echo "foo" > file1.txt
$ echo "bar" > file2.txt
$ grep -l foo * | xargs cat
foo
You have 2 files, and you are looking for the one with the string "foo" in it. Change cat with your command of choice to open files. Might try vi, emacs, nano, pico... (no, another flame war!)
You may want to try a different approach if there are several files that contains the string you are looking for... Just thought of only one file containing the string.

Command line tool to search docx file under ms dos or cygwin

Is there a command line tool that is able to search docx file under ms dos or cygwin ?
I have tried grep, it's not working with docx while working fine with txt file.
I know I could always convert the docx to txt 1st then search using grep, but I am wondering
is there a command tool that I can search directly under command line?
Thanks
i wrote a small bash script, which would help you:
#!/bin/bash
export DOCKEY="$#"
function searchdoc(){
VK1=$(cat "$#" | grep -i "$DOCKEY" | wc -c)
VK2=$(unzip -c "$#" | grep -i "$DOCKEY" | wc -c)
let NUM=$VK1+$VK2
if [ "$NUM" -gt 0 ]; then
echo $NUM occurences in $#
echo opening file.
gnome-open "$#"
fi
}
export -f searchdoc
echo searching for $DOCKEY ...
find . -exec bash -c 'searchdoc "{}" 2>/dev/null' \;
save it as docfind.sh and you can invoke
$#> docfind.sh searchterm
from any folder you want to scan.
After a trying out the stuff , I found the easiest way to do this is to use a linux utility to batch convert all docx files into txt files, then do grep with those txt files easily.
zgrep might work for you? It usually works in OpenOffice documents, and both are compressed archives containing XML:
zgrep "some string" *.xdoc
I have no .xdoc files to test this with, but in theory it should work...
You can use zipgrep, which calls grep on all files of a zip archive (which a docx file is).
You might be disappointed with the result, though, as it returns raw content of XML files containing both the text and XML tags.
save it as docfind.sh and you can invoke
Newbies like me might need to be told that for the .sh script to be executable from any directory, it needs to have the executable property set and be located in /usr/bin or elsewhere in your Path.
I was able to set up the nemo file manager in Linux Mint to open a terminal from any folder's context menu (information here).

Resources