Linux Rename List of Structural Pattern Flies What Are things I Have Learned


Given: List of Linux files contain structural format data with name
student ID Request form_Milind Jain - AIRBUS .doc Here

Needs to Replace: student ID Request form_Jaikumar_Selvaraj - AIRBUS .doc

1)needs to create source file name it is very simple ls > ls.sou
2)Needs to create the destination file
$ ls | awk -F"Milind Jain" '{print $1"Jaikumar Selvaraj"$2}' > ../ls.des
$ cat ls.sou | awk -F"Milind Jain" '{print $1"Jaikumar Selvaraj" $2}' >> ls.des

3)Now using ls.sou and ls.des merge this two files using mv source and destination.

I have felt This logic  will be little bit difficult,So, I have found simple solution in the following one.
$ ls | awk -F"Milind Jain" '{ print name=$1"Jaikumar Selvaraj"$2} END { print "mv" "$0" "name }'

1)Input files has some structural data pattern.
in the awk function create the source and destination variable.
using mv change the file name from source to destination.

2)List of the files will be(ls)
student ID Request form_Milind Jain - AIRBUS .doc

3)naming files should be
student ID Request form_Jaikumar selvaraj - AIRBUS .doc

4)Name should be changed from Milind Jain to Jaikumar Selvaraj

this things  we have been achieved by

#ls | awk -F"Milind Jain" '{ name = $1"Jaikumar selvaraj"$2} { print "mv "$0" "name}'
In the awk
Colon ' is important
equals to = is important
Double Quote " is important.

5)Finally I have been created the shell script file to rename it.
For sample is
mv student ID Request form_Milind Jain - AIRBUS .doc student ID Request form_Jaikumar selvaraj - AIRBUS .doc

$mv student ID Request form_Milind Jain - AIRBUS .doc student ID Request form_Jaikumar selvaraj - AIRBUS .doc
mv: target `.doc' is not a directory
shell is unable to find the file.because file is contain name with SPACE.

REASON: That is reason it is through error message like
file is not found, is not directory.

The above problem will be replaced by adding the Backward slash and space.
$ sed 's: :\\ :g' -i
Why two  backward slash - act as single singe slash.
b)sed 's:/:\\:g' sedlinux.txt [ change slash / into back slash \ ]

5.1)So, I have open the shell script file using search and replace I have change all the empty place with backward character then space.
space - > \space.

5.2)At the same time it is affecting other normal operation like
mv change into mv\
.doc change into .doc\

5.4)So, we need to do one more replace, for mv and .doc file.

5.5)Finally it has been done by following command.
[jaikumar@oc8012541851 dec]$ $ sed 's: :\\ :g' -i
[jaikumar@oc8012541851 dec]$ sed 's:mv/:mv:g' -i

Better Logical Program

1)Logical should straight forward and simple
2)using less variable.

No comments:
Write comments