Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Friday, December 2, 2011

Set backspace key for erasure on unix

Sometimes when we try to use backspace key on a unix terminal, it does not work as expected. Instead it prints caret and some special characters on command prompt.

There are two ways to handle it:
  • Add below command in .profile of the user account.
                          stty erase ^?
  • Run the following command. It will only set the backspace key for current session.
                          stty erase "press backspace key to print special characters"
          OR           stty erase ^?

stty command is used to set the terminal options. For detailed information, you can check its manual on unix by running command man stty

Saturday, July 17, 2010

Split single line into multiple lines in UNIX

There are so many ways to break a line in unix and i just found out two simple ways of doing it



  • Unix provides a command to directly split a line using length of new lines. There is a command 'fold' to do this:
          Syntax of the command is 
         fold - inputLine > outputLine
         e.g. fold -2000 file > outputFile.
         It will break all the lines in file  "file" into lines of maximum length 2000 characters.



  • Another way to do this is using sed or perl command. Using this command line can be broke around a character and also  minimum number of character can be defined in each new line
          Syntax is
          perl -pe 's/(.{1,199}[ ,])/\1\n/g'
           
            In this command, 
          .{1,199} - it will search the split character after 200 character only.
          [ ,] - split character is either space pr comma.
          \1\n - once split character is found, it will replace the line with first part of line (upto 200  character and then adds newline character.