I have an app that has a config file. Is there a way to replace all the text in the file with other text i have. Instead of using sed to modify the current file. Id like to just rip all the text from the file and add in my own file then save the changes, Ideally this will be run with the user signed in as the user or sudo as well so permissions should be ok.
file location: ~/Library/Application \Support/App/config_file.json
How about this?
cat < other_file > my-config.json
Related
I try to create a shortcut for macOS Monterey to export data from Tim (a time tracker) and save that data to a file.
I am able to do the first step (export data), but I have no idea how to do the second step (put the text in a file).
One way could be to use a shell script to export the data:
But this gives me an almost empty file:
$ cat tim.txt
Save text to file%
There must be a [better] way to save the data to a text file.
When I try to debug the first step, I get the correct output:
How can I save the text to a file (overwrite the file or create the file if it does not exist.)
After some digging I've found that it is more straightforward than I thought.
There seems to be a bug (or a IMO bad behaviour) in the shortcuts app, the suffix of the file is always .txt, but I prefer .json, so I need a third step to rename the file.
The problem I had was to change the directory to the desired output and use a relative filename from there.
Either I'm too stupid or I can't find the right command.
How can I create a simple YAML file using the ZSH terminal?
You can create yml file like these commands
echo "basic" > basic.yml or touch simple.yml
YAML is just a format so you can create any text file and just add an .yml or .yaml extension.
Command for creating files in zsh is touch
touch test.yaml
What people usually do is to just open a terminal text editor like nano or vim add the content and save as *.yml or *.yaml
I want to make a .txt file inside the same folder that contains all the filenames of said folder.
How can i do that?
Thanks.
you can do this in terminal by using
ls {DIR} >> {FILE}
for example if i wanted to write a file called 'ls.txt' of all the files on the desktop i could use
ls /Users/corvinmcpherson/Desktop/ >> /Users/corvinmcpherson/Desktop/ls.txt
you can also create one using automator like this:
Or you can create an Automator Workflow like this as a Service, so that all you have to do is right click the folder, click the service and this text file will appear in the folder, with the name of the folder.
I have a text file fold.txt that contains one line fold_nam:
$ cat fold.txt
fold_nam
This name in the the text file is an output that was created during a program run of a folder's name that now contains other files that I need to work with.
I am writing a big script and now I need to enter this folder and I need to get the name from the text file. I tried several things but cannot really work it out.
There's no need to use cat:
cd $(<fold.txt)
If you want to read the line into a variable: read -r folder_name < fold.txt
You should be able to do this:
cd $(cat fold.txt)
or
cd `cat fold.txt`
Hi I'm using a user script in xcode to do some work for me. The first part of the script needs to take the piped content of the selected file and store it in a temp file. Doing some reading on redirects I found this:
#!/bin/bash
/Users/derek/projects/Crema/Classes/CoffeeFormController.m.uncrustify<&0
My understanding is that it should take all the piped in content and store it in the file The Xcode user script is set to pass the Entire Document to the script so this is effectively storing the current version of the file, regardless of whether the user has saved it or not.
However I get this error:
/var/folders/yo/yoISLF-4EYqDjeiZTSIpOU+++TI/-Tmp-/B047C058-C538-463A-848C-158EB82DAAFE-3501-000033543EE408FE:
line 14: /Users/derek/projects/Crema/Classes/CoffeeFormController.m.uncrustify:
No such file or directory
Which makes sense because the file does not yet exist. The command should create it. I also tried using touch to first create the file, but then it tells me it doesn't have permission to write the file ?????
Does anyone know who to store the current contents of the piped in file in xcode user scripts?
cat reads from stdin by default:
cat > /Users/derek/projects/Crema/Classes/CoffeeFormController.m.uncrustify