Concatenating a variable name with text in Unix shell scripting

I have a variable named FILENAME1  whose value is yyyymmdd.csv
I want to extract the first 8 characters from the variable and then concatenate _m.csv to it
I'm new to unix shell scripting, but sure this can be done  
VBStudentAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
FILENAME1=`echo $FILENAME1|perl -pe 'substr($_,8)="_m.csv"'`
or
FILENAME1=${FILENAME1:0:8}_m.csv
should work in ksh
0
 
ozoCommented:
I'm not sure which shell you are using, but
echo $FILENAME1 | perl -pe 'substr($_,8)="_m.csv"'
is one way
0
 
ozoCommented:
in some shells, such as bash or ksh, you could do
echo ${FILENAME1:0:8}_m.csv
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
manav_mathurCommented:
new_variable=`echo $FILENAME1 | sed 's/\./_m./'`
or
new_variable=`echo ${FILENAME1:0:8}_m.csv`
or
new_variable=`echo $FILENAME1 | perl -pe 'substr($_,8)="_m.csv"'`
 
0
 
VBStudentAuthor Commented:
echo $FILENAME1 | perl -pe 'substr($_,8)="_m.csv"'
This syntax works well, however, how do I assign the output to the variable name FILENAME1?

I tried FILENAME1 = $FILENAME1|perl -pe 'substr($_,8)="_m.csv"' but it stripped the original filename and left me with _m.csv
0
 
ozoCommented:
You still didn't say which shell you are using
FILENAME1=`echo $FILENAME1|perl -pe 'substr($_,8)="_m.csv"'`
would work in some shells
0
 
VBStudentAuthor Commented:
I'm using ksh shell
0
All Courses

From novice to tech pro — start learning today.