Find the answer to your Linux question:
Results 1 to 2 of 2
Hi Im trying to extract the first seven characters of everyline of a file, then set those seven characters as a variable. The text file is generated by: Code: who ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    9

    Extract First Seven Characters

    Hi Im trying to extract the first seven characters of everyline of a file, then set those seven characters as a variable.

    The text file is generated by:
    Code:
    who >> who.txt
    So Im trying to get the usernames which on my system are always seven characters. Then store them as $var, then run
    Code:
    MyScript $var
    Then get the username off of the next line, repeat.

    Another way would be to extract everything up to the first space character.

    Ive been trying to get this done but I always end up just extracting the whole line.

    Any help would be great.

    Thanks!

  2. #2
    Linux Newbie radoulov's Avatar
    Join Date
    Sep 2007
    Posts
    111
    You can do something like this:

    Code:
    who | 
      while read u j; do
    	  : # do something with "$u" here
    	done
    Or play with who -q if your who program supports that option.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...