I'm assuming I can put this line in a script so it might look like:
#!/bin/sh
# read files
cat ${WORKFILE} | while read file
do
sed 's/}/}Model_Type={t}, ModelName={m}/1' $file
done
NOTE: ${WORKFILE} is a text file that has the listing of all the files I want to edit.
---------- Post updated at 02:46 PM ---------- Previous update was at 02:32 PM ----------
After running the above script it is placing "ModelType={t}, ModelName={m}" after EVERY right curly bracket in the file. There are multiple variables in each file, which look like this: {v}. So I am getting multiple incertions in each file.
---------- Post updated at 02:52 PM ---------- Previous update was at 02:46 PM ----------
After putting this in a loop I can see it do two things.
1st: I am getting output to the screen, but it is not writting the addition to the file
2nd: The code is adding multiple instances of "Model_Type={t}..." for each file may contain multple instances of variables, which look like: {v} where "v" is the variable letter., so, In the screen output it is adding "Model_Type=..." every time it sees another right curley bracket.
My entire script looks like this:
#!/bin/sh
####### MAIN SCRIPT #################
host=$1
DATE=`date '+%m%d%y_%H%M'`
CLISESSID=$$
SPECROOT=d:/
SCRIPTHOME=${SPECROOT}/custom/scripts/TestEventFolder
WORKFILE=${SCRIPTHOME}/Event_OneLine.txt
#WORKFILE=${SPECROOT}/tmp/worklist.txt
LOGFILE=${SCRIPTHOME}/LOGFILE_${DATE}.txt
SEARCHDIR=${SPECROOT}/Events
CLIMNAMEWIDTH=64
CLIPATH=${SPECROOT}/vnmsh
export CLISESSID CLIMNAMEWIDTH CLIPATH host DATE SPECROOT SCRIPTHOME WORKFILE LOGFILE
cd ${SCRIPTHOME}
# get event files
ls Event* > ${WORKFILE}
# read files
cat ${WORKFILE} | while read file
do
sed 's/}/}Model_Type={t}, ModelName={m}/1' $file
done
Screen Output:
d "%w- %d %m-, %Y - %T"}Model_Type={t}, ModelName={m} - A "caSwitchLinkUpTrap" event has occurred, from {t} device, named {m}.
caSwitchLinkUp trap signifies that the caSwitchIfOperStatus object for a switch interface left the down state and transitioned into
te). This other state is indicated by the included value of caSwitchIfOperStatus.
aSwitchIfSwitchIndex = {I 1}Model_Type={t}, ModelName={m}
aSwitchIfIndex = {I 3}Model_Type={t}, ModelName={m}
aSwitchIfAdminStatus = {T caSwitchIfAdminStatus 4}Model_Type={t}, ModelName={m}
aSwitchIfOperStatus = {T caSwitchIfOperStatus 5}Model_Type={t}, ModelName={m}
event [{e}Model_Type={t}, ModelName={m}])
As can be seen, when the script is run it is looking for the right curley bracket in EACH LINE of the file. Is there a way to have the sed operation look at the FIRST LINE ONLY?