Today I am trying to abbreviate a line through linux bash script and found it so easy to do it with scripting so I am posting it here.
Here I have user read command to read one line (ended with pressing enter key) and the program read the entire line (one word at a time) and abbreviate with the first letter of each word.
#!/bin/bash
# Author Subhroneel Ganguly
# Date 21.10.2014
echo Enter String :
read line
# read reads an entire line and stores it in line variable.
abbr=""
#initializing abbr to ""
for wrd in $line
do
# loop reading one word per iteration
abbr=$abbr${wrd:0:1}"."
# :0:1 is position:number of character
done
echo ${abbr^^}
# ^^ convert the entire string (abbr not $abbr) to upper case.
For more tutorial subscribe to my youtube channel : https://www.youtube.com/subhro190776
Here I have user read command to read one line (ended with pressing enter key) and the program read the entire line (one word at a time) and abbreviate with the first letter of each word.
#!/bin/bash
# Author Subhroneel Ganguly
# Date 21.10.2014
echo Enter String :
read line
# read reads an entire line and stores it in line variable.
abbr=""
#initializing abbr to ""
for wrd in $line
do
# loop reading one word per iteration
abbr=$abbr${wrd:0:1}"."
# :0:1 is position:number of character
done
echo ${abbr^^}
# ^^ convert the entire string (abbr not $abbr) to upper case.
For more tutorial subscribe to my youtube channel : https://www.youtube.com/subhro190776
No comments:
Post a Comment