Issue with File Renaming

I am trying to perform some validations on the source files. the script has file name pattern as an argument.The Input file has Single quotes in the filename . I want to remove those single quotes and split the file into 2 parts. below is my code

FILE_NAME=$1
if [ -f $FILE_NAME ]
then 
    echo "\n Files are available to process \n"
else 
    echo "\n File does not exist: Process is Terminating \n"
    exit 1
fi

for FILE_NAME in $FILE_NAME
do
eval mv -f '$FILE_NAME' $File_NAME
sed -ne '2,1p' $File_NAME > Hdr_$File_NAME
sed -ne '3,$p' $File_NAME > Dtl_$File_NAME
done

The problem is the split Files get renamed with zero bytes and the Single quotes still exist but the original files get renamed with data existing.

Below is the example of scenario

I am receiving multiple files in the below format

'abc.def.ghi.jkl'
'abc.def.xty.xyz'
'abc.def.rew.ter'

I want to split and rename each of these files with out the single quotes as below.

Hdr_abc.def.ghi.jkl
Hdr_abc.def.xty.xyz
Hdr_abc.def.rew.ter

Dtl_abc.def.ghi.jkl
Dtl_abc.def.xty.xyz
Dtl_abc.def.rew.ter

But instead the output is with Zero bytes for each file.

Hdr_'abc.def.ghi.jkl'
Hdr_'abc.def.xty.xyz'
Hdr_'abc.def.rew.ter'

Dtl_'abc.def.ghi.jkl'
Dtl_'abc.def.xty.xyz'
Dtl_'abc.def.rew.ter'

but the original files are Renamed and it has all the data.

abc.def.ghi.jkl
abc.def.xty.xyz
abc.def.rew.ter

Can somebody help.

Thanks.

you don't want the first line in the splitted file? or its a mistake.

try:

for FILE in $(ls -1 \'*)
do
 
file=${FILE#\'}
file=${file%\'}

mv -f "$FILE" "$file"

file1=$(echo "$file" | sed -e "s|^|Hdr_|g")
file2=$(echo "$file" | sed -e "s|^|Dtl_|g")

sed -ne '1,2p' "$file" > $file1
sed -ne '3,$p' "$file" > $file2
 
done

this will put first two line in one file and rest in another. (as per you code)

I rewrote your script a little:

splittinquoted:

FILE_NAMES="$@"

if [ -f "$1" ]
then
    echo "\n Files are available to process \n"
else
    echo "\n Specified files do not exist: Process is Terminating \n"
    exit 1
fi

for quoted_file_name in $FILE_NAMES
do
  file_name=${quoted_file_name//\'/}
  mv -f $quoted_file_name $file_name
  sed -ne '1,2p' $file_name > Hdr_$file_name
  sed -ne '3,$p' $file_name > Dtl_$file_name
done

Usage: ./splittingquoted \'*\'

bash solution using parameter expansion.

# ls
'abc.def.ghi.jkl'       'abc.def.rew.ter'       'abc.def.xty.xyz'

# for file in \'*;do echo mv "$file" "${file//\'/}";done
mv 'abc.def.ghi.jkl' abc.def.ghi.jkl
mv 'abc.def.rew.ter' abc.def.rew.ter
mv 'abc.def.xty.xyz' abc.def.xty.xyz

# for file in \'*;do mv "$file" "${file//\'/}";done

# ls
abc.def.ghi.jkl abc.def.rew.ter abc.def.xty.xyz

yeah, its better to provide the new filenames at the time of redirection.

after elimination of :

file1=$(echo "$file" | sed -e "s|^|Hdr_|g")
file2=$(echo "$file" | sed -e "s|^|Dtl_|g")

its reduced to:

for FILE in $(ls -1 \'*)
do
 
file=${FILE#\'}
file=${file%\'}

mv -f "$FILE" "$file"

sed -ne '1,2p' "$file" > Hdr_$file
sed -ne '3,$p' "$file" > Dtl_$file
 
done

Thankyou all......its working