macOS How to read Pages/Numbers file in command line? - macos

macOS How to read Pages/Numbers file in command line ?
I have userd 'cat'
cat /Users/administrator/Downloads/test.pages
but get:
????(??#?-QEQEQEQEQEQEQEQE?kYe??Ȍ?"8?,?9A?i;??1]?????=.SE[????Sqs-?,?iY??3]]QEQEQEQEQEQEQEQE??????(??(??(??(??(??(??(??(??(??(??????(??(??(??(??
addtional
I can use cat to watch .md file

Pages/Numbers files are .zip archives of binary files, not text files. In order to read them on the command line, you'll need a special tool, though I don't believe one exists at the moment

Related

Unzip only files that start with a certain word

I have a zip archive (let's call it archive) and let's say I want to go through some directories and finally extract ONLY the files that start with the word 'word'. Some thing similar to:
archive.zip/dir1/dir2/word***.csv
What is the command that could do this without having to extract the whole file (very big file)?
I tried this command line:
unzip -p archive.zip dir1/dir2/word***1.csv >destination
But this only extracts one file not all files that start with 'word'
You should do
unzip -p archive.zip dir1/dir2/word*1.csv >>destination.csv
The > truncates file destination.csv to zero length giving you the impression that only one file was unzipped, while >> creates the file if not present, otherwise appends to it which is the required behavior.
Reference : Check I/O redirection

How do I use grep command to search in .bz2.gz.bz2 file?

Basically I have .bz2.gz.bz2 file which on extraction gives a .bz2.gz file and on again extraction gives .bz2 file. In this .bz2 file, is my txt file which I want to search on using grep command. I have searched for this but I got bzgrep command which will only search in bz2 file and not the corresponding .gz.bz2 file and give me no results.
Is there a command in unix system which will recursively search in a zipped archive for zipped archive and return results only when it finds the txt file inside it?
P.S: the txt file may be deep in the archive to level 10 max. I want the command to recursively find the txt file and search for the required string. And there will be no other than an archive inside the archive until the txt file level.
I'm not sure I fully understand but maybe this will help:
for i in /path/to/each/*.tar.bz2; do
tar -xvjf "$i" -C /path/to/save/in
rm $i
done
extract all `tar.bz2` and save them in directory then remove the `.bz2`
Thnx for sharing your question.
There are a couple of strange things with it though:
It makes no sense to have a .bz2.gz.bz2 file, so have you created this file yourself? If so, I'd advise you to reconsider doing so in that manner.
Also, you mention there is a .bz2 that would apparently contain different archives, but a .bz2 can only contain one single file by design. So if it contains archives it is probably a .tar.bz2 file in which the tar-file holds the actual archives.
In answer to your question, why can't you write a simple shell script that will unpack your .bz2.gz.bz2 into a .bz2.gz and then into a .bz2 file and then execute your bzgrep command on that file?
I do not understand where it is exactly that you seem to get stuck..

How to stop new line conversion when zipping a Windows text file on a Unix machine

I want to zip a windows .cmd file on an OSX server, using the zip command line tool.
templateName="Windows_Project_Template"
zip -r -T -y -9 "${templateName}.zip" $templateName
When the file is unzipped on a windows machine all the new line carriage returns are converted and so the text file comes out without any new line formatting on a windows machine. How can I work around this?
Thanks
While not a perfect solution (I can't find an option to handle everything as binary), you can force the \r\n with the --to-crlf option:
-l
--to-crlf
Translate the Unix end-of-line character LF into the MSDOS convention CR LF. This option should not be used on binary files. This
option can be used on Unix if the zip file is intended for PKUNZIP under MSDOS. If the input files already contain CR LF, this
option adds an extra CR. This is to ensure that unzip -a on Unix will get back an exact copy of the original file, to undo the
effect of zip -l. See -ll for how binary files are handled.
Be careful, if the file already contains \r\n you will get \r\r\n.

Read a text file and use data in it as arguments in a command

I am writing a script to run in single user mode on a mac. I am having an issue because I am not able to figure out how to read data from a text file that contains this information
Guest
Shared
user
as three lines of unformatted text. I need to cd into these three directories which are subdirectories of /Users in order and run commands in each of the directories. The part Im having an issue with is only the reading of the text data line by line into cd /Users/$IneedToReadDataHer$/. If anyone knows how to do this it would be greatly appreciated.
cat file | while read line
do
cd /Users/"$line"/
# do something else
done

Compress command results in corrupted zip file

I have a script set up to rotate some log files in windows, and as part of the process I'd like it to automatically compress the rotated file. To do this I use the command
compress source.file destination.file.zip
However, if I try to open the file, I get the message "The Compressed (zipped) Folder is invalid or corrupted"
I've tried compress with -Z, and I get the same message. What am I doing wrong?
compress output is not ZIP file format compatible, it uses the LZW algorithm.
The only way to "open" a compressed file is with uncompress or gunzip.
Windows ports of common Unix commands, including compress and gzip/gunzip available here.
EDIT: To produce ZIP files from the command line in Windows, you can use something like 7-Zip, which includes a command line application (7z.exe). The Unix commands linked above also include zip.exe for manipulating ZIP files from the command line.

Resources