axtur
asked on
Unix Shell script
I need to write a small sample script with the next features, it shouldn't be more thatn 10 lines of code:
I need a program that, for all the files (whose name is given as a parameter), will create a copy of them, changing the last 2 lines of each file for the content of an existing file in the current directory called ABC. The name of the new file should be the same as in the original file, but adding the string "mod" at the end.
I need a program that, for all the files (whose name is given as a parameter), will create a copy of them, changing the last 2 lines of each file for the content of an existing file in the current directory called ABC. The name of the new file should be the same as in the original file, but adding the string "mod" at the end.
Is this an assignment question?
please post what you`ve done so far and tell us where you have problems
ASKER
This is for a friend who needs help, I should know how to do this, but I've forgotten completely!!
I've done this so far:
for i
do
echo "$i = "
cat $i
done
This code shows on screen the content of the files given as parameters, show the filename before the content of the file.
I've done this so far:
for i
do
echo "$i = "
cat $i
done
This code shows on screen the content of the files given as parameters, show the filename before the content of the file.
for i in "$*"; do
cp "$i" ABC/
done
cp "$i" ABC/
done
ASKER
it looks like this won't change the content of the last two lines of each file and won't rename the file to existing_filenameMOD (concatenate the string "MOD" to the filename), how can I add such features to the existing script?
for i in "$*"; do
cp "$i" ABC/"$i"mod
cat existing-file-with-2-lines >> ABC/"$i"mod
done
cp "$i" ABC/"$i"mod
cat existing-file-with-2-lines
done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.