2) Write a C Shell script that will add the current date to the end of a filenam
ID: 3889247 • Letter: 2
Question
2) Write a C Shell script that will add the current date to the end of a filename. E.g, if today is Dec 25, 2017, then the shell script should change the filename to: filename 20171225 The script should read the filename from the command line. Hence, if we named this script adddate then execution of this command should look like: >>addate filename 3) Write a C Shell script that will remove dates added with the script written in Problem #2. Note: this script should also work when there is a dot in the filename. E.g., the code should work for any filename of the form... foo.20101225 foo.foo. 20101225 foo.foo.foo.20101225 foo.foo.foo.*.20101225 Output file names for the examples above should be: foo foo. foo foo.foo.foo etc.
Explanation / Answer
#!/bin/csh
set ifile = $argv[1]
#determine total number of fields to keep
@ lf = `echo $ifile | awk ‘BEGIN {FS=”.”} END {print (NF-1)}’`
set ofile = `echo $ifile | cut –d. –f1-${lf}`
echo “moving file $ifile to $ofile”
mv $ifile $ofile
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.