Difference between revisions of "Editing Text"

From LinuxMCE
Jump to: navigation, search
(The cat-way)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
[[category:tutorials|Text]]
 +
 +
{| align="right"
 +
  | __TOC__
 +
  |}
 
== The [[vim]]-way ==
 
== The [[vim]]-way ==
 
<pre>vim /path/to/file</pre>
 
<pre>vim /path/to/file</pre>
Line 28: Line 33:
 
Content of the
 
Content of the
 
file with linefeeds.
 
file with linefeeds.
EOF<pre>
+
EOF</pre>
 
Writes everything betwen the cat and the EOF to the given file.
 
Writes everything betwen the cat and the EOF to the given file.
  
Line 38: Line 43:
 
EOF</pre>
 
EOF</pre>
 
Appends everything betwen the cat and the EOF to the given file without overwriting it.
 
Appends everything betwen the cat and the EOF to the given file without overwriting it.
 
 
  
 
== The echo-way ==
 
== The echo-way ==
<pre>echo "contents" > /path/to/file<pre>
+
<pre>echo "contents" > /path/to/file</pre>
 
Writes everything betwen " " to the given file (no linefeeds possible).
 
Writes everything betwen " " to the given file (no linefeeds possible).
  
 
Attention: The file is being overwritten.
 
Attention: The file is being overwritten.
  
<pre>echo "contents >> /path/to/file<pre>
+
<pre>echo "contents >> /path/to/file</pre>
 
Appends everything betwen " " to the given file without overwriting it.
 
Appends everything betwen " " to the given file without overwriting it.
  

Latest revision as of 05:39, 9 October 2012


The vim-way

vim /path/to/file

Make the changes with vim: i: insert mode

w! write file
x! exit vim and save
q! exit vim without saving


The nano-way

nano /path/to/file
or
nano -w /path/to/file
(this will disable automated line-breakes)


Make the changes with nano:

CTRL+O: Write file

CTRL+X: Exit the program (you will be asked if you want to save changes)

CTRL+W: Search for a string


The cat-way

cat > /path/to/file << "EOF"
Content of the
file with linefeeds.
EOF

Writes everything betwen the cat and the EOF to the given file.

Attention: The file is being overwritten.

cat >> /path/to/file << "EOF"
Content of the
file with linefeeds.
EOF

Appends everything betwen the cat and the EOF to the given file without overwriting it.

The echo-way

echo "contents" > /path/to/file

Writes everything betwen " " to the given file (no linefeeds possible).

Attention: The file is being overwritten.

echo "contents >> /path/to/file

Appends everything betwen " " to the given file without overwriting it.

The perl-way

perl -e 'print "Content of the\nfile with linefeeds"' > /path/to/file

Writes everything betwen " " to the given file (\n represents linefeeds).

Attention: The file is being overwritten.

perl -e 'print "Content of the\nfile with linefeeds"' >> /path/to/file

Appends everything betwen " " to the given file without overwriting it (\n represents linefeeds).