I need to configure a server with a few files and I want to do it programmatically.
I need to create files say /home/a.config, /var/spool/b.config, /etc/c.config
Files above have some contents (multi lines).
I want to create ONE shell script which can create all three file with multiple lines (around 10). I would like to know the how can I use CAT
command to do that. (inside shell script).
I am looking something like this
echo " going to create /home/a.config" cat "HOW CAN I HAVE MULTIPLE LINES HERE?? " > /home/a.config
thanks
To create a new file, run the "cat" command and then use the redirection operator ">" followed by the name of the file. Now you will be prompted to insert data into this newly created file. Type a line and then press "Ctrl+D" to save the file.
To create a new file run the cat command followed by the redirection operator > and the name of the file you want to create. Press Enter type the text and once you are done press the CRTL+D to save the files.
To make a new file in Bash, you normally use > for redirection, but to append to an existing file, you would use >> . Take a look at the examples below to see how it works. To append some text to the end of a file, you can use echo and redirect the output to be appended to a file.
You can create a file using $ cat > a.txt. If you need to have a file with specific content, type $ echo content > filename. Show activity on this post. Show activity on this post. Instead of using filenames a..z i prefer using numbers. Show activity on this post. echo CONTENT | tee PATH…
Most of the time, we use shell scripting to interact with the files. Shell scripting offers some operators as well as some commands to check and perform different properties and functionalities associated with the file.
Creating a Simple Text File with PowerShell. In our first example, we'll create a text file with text in a location where the running user can create and add text to the file. In our first line, we'll actually create the file with a sentence and then call our next function to add content in the form of another sentence to the same file.
You can create a file using $ cat > a.txt. If you need to have a file with specific content, type $ echo content > filename. Show activity on this post. Show activity on this post.
You can use a here document:
cat <<EOF >/home/a.config first line second line third line EOF
You can place several of these in the same script.
On OS-X the command should be:
cat > filename <<- "EOF" file contents more contents EOF
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With