Re: help in shell scripting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Nabin Limbu" <nlimbu@xxxxxxxxxxxxxxxx> writes:

> Hi,
>
> In my script, I need to read a file name and change its first 
> character of file name with another predefined character. How can I 
> do that with shell scripting.
>
> for example:
>
> if A = "glow"
>
> then, B should be "blow"  ("g" replaced by "b")
> ( glow  -> blow )


Here is one way but it assumes all file names begin with lower or
upper case letters:

#!/bin/bash
## Slurp first command line argument as predefined letter
predefined_char=$1
## Get rid of var $1
shift
## Get a list of file names in current directory
for ii in $(ls);do
   ## Push existing name ($ii) thru sed to drop first letter
   ## and insert predefined letter
   ## NOTE: The quations used in line below are VERY important
   echo $ii|sed 's/^[a-zA-Z]/'"$predefined_char"'/'
done

To add in filename beginning with letters to use:
sed 's/^[a-zA-Z0-9]/'"$predefined_char"'/'


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux