Results 1 to 7 of 7
Hi,
I need some help please. I'd like to know if it's possible to create and insert some text into a file with one (or a couple) of command line ...
- 02-01-2005 #1Just Joined!
- Join Date
- Nov 2004
- Location
- Leicester, UK
- Posts
- 7
Creating and editing files with CLI
Hi,
I need some help please. I'd like to know if it's possible to create and insert some text into a file with one (or a couple) of command line statements.
For example, I want to create a file called monkey.nuts - and on the same command line add the text "Monkey Nuts" into it. It would also be acceptable to create the file first - and then add the "Monkey Nuts" text on a new line.
So something like;
vim -[arg] "monkey nuts" > monkey.nuts
Or piping the command into the file. How do I create a file in the first place?
I hope this makes sense!
Thanks for any help
- 02-01-2005 #2Wow.. I didn't realize how dirty that sounds. But that's one way to do it.Code:
touch monkey.nuts; echo Monkey Nuts > monkey.nuts
The touch command opens a file and immediately closes it, and if there is no file, creates it. It's a good way to update the modification dates on old files without actually having to open them up, save them, and close them.
To put more than one line of commands on a single line in BASH, use a semicolon ; The echo command simply prints back whatever text you send it, and the > redirects the output of echo to the file you specify.Registered Linux user #270181
TechieMoe's Tech Rants
- 02-01-2005 #3Just Joined!
- Join Date
- Nov 2004
- Location
- Leicester, UK
- Posts
- 7
You sir, have made my day! I knew it was going to be something nice and simple - it's just a mine field when you dont know where to start!!
Thank you so much for the quick reply.
- 02-01-2005 #4Just Joined!
- Join Date
- Nov 2004
- Location
- Leicester, UK
- Posts
- 7
Oh!
Wait - there's something else if you dont mind.
Say then I do this:
touch map.gmt; echo line 1 > map.gmt
then I want to add another line of text either after or below the line 1 I originally created (without overwriting line 1)
Is there an echo command to appened or add on new line? So I could keep adding new lines to the file, line 2, line 3, line 4?
Thanks again!
- 02-01-2005 #5
Yes, you can use cat to append to the end of a file instead of overwriting it.
I don't remember exactly the syntax to do this right now, but you can do a little research by typing man cat.

I believe the >> operator appends lines to the end of a file in BASH as well. Here's a page that mentions it.Registered Linux user #270181
TechieMoe's Tech Rants
- 02-01-2005 #6Just Joined!
- Join Date
- Nov 2004
- Location
- Leicester, UK
- Posts
- 7
Thanks for the help
- 02-01-2005 #7
Or use
which will append instead of overwrite.Code:echo blaat >> filename
I\'m so tired .....
#200472


Reply With Quote
