bash Linux how to get first or last letters of a word -

bash Linux how to get first or last letters of a word

To get the first X letters of a word:

It's very simple you can just pipe it to head with

  • -c 1 (gives the first letter and so on)
  • -c2 (2 gives the first 2 letters). 

 echo "dsjfsdlksjdklf;jlsd;kflasdj;kl"|head -c 2

Returns ds
 

To get the last X letters of a word:

Now we use tail with -c but it works differently.  You will want to start with 2 otherwise you will get the end of the string which is nothing.

 echo "dsjfsdlksjdklf;jlsd;kflasdj;kl"|tail -c 2

Returns "l"

 echo "dsjfsdlksjdklf;jlsd;kflasdj;kl"|tail -c 3

Returns "kl"
 


 


  • Install Windows From a Linux TFTP Server instead of using WDS Solution
  • How To Secure Samba NMBD/SMBD to bind to a specific IP address
  • tftp: client does not accept options - solution if you are using UEFI PXEBoot disable it!
  • Linux how to view video card make and exact model
  • Authentication refused: bad ownership or modes for directory /home/user SSH Public Key Authentication Failed Solution
  • How to Update Linux /usr/share/misc/pci.ids
  • pcimodules and lspci not working alternative solution
  • How to disable Google Fonts in Wordpress
  • Unable to load dynamic library /usr/lib64/php/modules/php_openssl
  • mysqld in Linux hacked
  • W: GPG error: http://archive.debian.org squeeze Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY AED4B06F473041FA NO_PUBKEY 64481591B98321F9
  • cannot mount kvm ntfs image
  • h264 DVR security camera footage cannot be played
  • dhcpd.conf how to secure so only known and allowed clients will be given dhcpd IP address leases
  • Thunderbird E-mail List Blank White but e-mails still clickable and viewable
  • css responsive images
  • responsive table without changing much code solution
  • yum how to install old obsolete packages
  • PHP Howto Store Value of Included File Output Into Variable
  • PHP Migration from 5.3 to 5.4+ and dealing with deprecated functions