I have a txt file on unix that I recently edited using vi, how do I convert line 18-30 all to lowercase?? What's the command for this on unix?? thanks
Uppercase to lowercase on unix?
I don't have access to 'vi' so the following may be of no use to you.
If you can run 'vim' on your system, the transformation is easy: move your cursor to line 18 with ':18', then press SHIFT-v, cursor down until the selection encloses line 30, then press 'u'.
Reply:There is no magic 'canned' UNIX command that will do this. You can get creative and execute this from the command line:
awk ' NR%26gt;=18 %26amp;%26amp; NR%26lt;=30 { for( i = 1; i %26lt;= NF; i++ ) $(i)=toupper($(i));} { print; }' %26lt;file.txt %26gt;nfile.txt
You cannot update the file in place, so you will need to write it out to a new file and move (mv) it back if you must have the changes back under the original file name.
Reply:Most likely perl is on the system. Here is a small perl script to do it.
Name the file lower.pl
#!/bin/perl
# The above line has to be the first line in the file.
$line=1;
while( %26lt;%26gt; )
{
if ( $line %26gt;= 18 %26amp;%26amp; $line %26lt;=30 )
{
$_ =~ tr/A-Z/a-z/; # convert to lower case
}
print $_;
$line++;
}
Run it like this:
chmod +x lower.pl; lower.pl yourfilename %26gt; yourfilename.new
yourfilename.new now contains the converted file.
Reply:http://vim.wikia.com/wiki/Switching_case...
In VIM, the command "guu" drops the entire line's case. So to do those lines, go to line 18 with "18G" then do the next 21 lines with "21guu".
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment