Bash grep with date comparison
Clash Royale CLAN TAG#URR8PPP
So, I have basically automated a majority of client license expiration reports and license renewals for our clients (I grep files for 31-dec-2018 and then echo the information into a text file that runs on another script to sed the contents based on the strings and runs the old license against lmcrypt and saves it as a new name based on the replacement string)... anywho (enough background info)...
I'd like to create a bash script that will take any files that will grep for a string that is the same in all files that don't run correctly:
(filename):line #:Feature has expired
FLEXlm error: -10,227
For further information, refer to the FLEXlm End User Manual,available at "www.globetrotter.com".
Then find the lines that contain dates that have passed already and remove those sections.
Example:
Today's date would be 14-JAN-2019
License file I am renewing but contains expired features:
SERVER licserver 001122334455
USE_SERVER
VENDOR company
FEATURE Software_F1 company 6.0 1-feb-2019 1 SIGN="0B7A 39A6 41A1
3482 0F3C 304E DFE5 A8C6 B2BC 9DA0 6759 43F6 7D54 4B6A E62B
04F4 1AC5 96BA 138A DD42 48D6 1979 4DF9 7171 ED9B 28A1 D847
21C4 45D0 8D05"
FEATURE Software_F2 company 6.0 31-dec-2018 1 SIGN="115B CDA3 8141
AD9B 6127 59A3 1B71 0D15 5D37 229F F358 031E D5BA 0290 F601
1FC9 A64F 7215 CB54 6CE8 493D 9008 3314 AA8C A0FA 166E E54C
49AC EF93 00E4"
I would like to insert a snippet into the bash script that will remove the FEATURE line and the SIGN code, so that would be 4 lines. So I was thinking find the line number of a date that has past today's date, remove 4 lines, and continue. Maybe an in place sed? And to get even fancier, we keep a notes.txt file and timestamp when we update a license file. I'd like to automatically insert something like this:
notes.txt:
1-JAN-2019 @ 11:33AM:
Modified (filename).lic and removed expired features:
(all lines removed)
Updated date on (filename).lic to (newfilename).lic.
The existing script that scans for 31-dec-2018 is this:
find $1 -type f -not -path '*/__A*' -exec grep -l -i "31-dec-2018" ; > ~/tmpfind.log
rm -rf ~/tmpfileignored.log
cat ~/tmpfind.log | while read line; do
##tempdirname1=`echo $line | sed 's%/[^/]*$%/%'`
tempdirname1=`echo "$line%/*"`
tempfilename1=`echo "$line##*/"`
echo "Directory: $tempdirname1"
echo "Filename: $tempfilename1"
if [ -f "$tempdirname1/sweeplinux.txt" ]
then
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2018/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
else
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2019/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
fi
done
I have another script that finds all "sweeplinux.txt" files and does an inplace sed to take the 2nd to last string to search for and replaces it with the last string of each line and then passed it to lmcrypt and has the output file the 2nd string in the file.
I am working on something like this now, but am kind of stuck doing the date comparison and erasing the 4 lines of the expired feature.
If you help me figure it out and live in Houston, TX, I will take you to dinner at a steakhouse.
bash sed date
add a comment |
So, I have basically automated a majority of client license expiration reports and license renewals for our clients (I grep files for 31-dec-2018 and then echo the information into a text file that runs on another script to sed the contents based on the strings and runs the old license against lmcrypt and saves it as a new name based on the replacement string)... anywho (enough background info)...
I'd like to create a bash script that will take any files that will grep for a string that is the same in all files that don't run correctly:
(filename):line #:Feature has expired
FLEXlm error: -10,227
For further information, refer to the FLEXlm End User Manual,available at "www.globetrotter.com".
Then find the lines that contain dates that have passed already and remove those sections.
Example:
Today's date would be 14-JAN-2019
License file I am renewing but contains expired features:
SERVER licserver 001122334455
USE_SERVER
VENDOR company
FEATURE Software_F1 company 6.0 1-feb-2019 1 SIGN="0B7A 39A6 41A1
3482 0F3C 304E DFE5 A8C6 B2BC 9DA0 6759 43F6 7D54 4B6A E62B
04F4 1AC5 96BA 138A DD42 48D6 1979 4DF9 7171 ED9B 28A1 D847
21C4 45D0 8D05"
FEATURE Software_F2 company 6.0 31-dec-2018 1 SIGN="115B CDA3 8141
AD9B 6127 59A3 1B71 0D15 5D37 229F F358 031E D5BA 0290 F601
1FC9 A64F 7215 CB54 6CE8 493D 9008 3314 AA8C A0FA 166E E54C
49AC EF93 00E4"
I would like to insert a snippet into the bash script that will remove the FEATURE line and the SIGN code, so that would be 4 lines. So I was thinking find the line number of a date that has past today's date, remove 4 lines, and continue. Maybe an in place sed? And to get even fancier, we keep a notes.txt file and timestamp when we update a license file. I'd like to automatically insert something like this:
notes.txt:
1-JAN-2019 @ 11:33AM:
Modified (filename).lic and removed expired features:
(all lines removed)
Updated date on (filename).lic to (newfilename).lic.
The existing script that scans for 31-dec-2018 is this:
find $1 -type f -not -path '*/__A*' -exec grep -l -i "31-dec-2018" ; > ~/tmpfind.log
rm -rf ~/tmpfileignored.log
cat ~/tmpfind.log | while read line; do
##tempdirname1=`echo $line | sed 's%/[^/]*$%/%'`
tempdirname1=`echo "$line%/*"`
tempfilename1=`echo "$line##*/"`
echo "Directory: $tempdirname1"
echo "Filename: $tempfilename1"
if [ -f "$tempdirname1/sweeplinux.txt" ]
then
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2018/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
else
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2019/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
fi
done
I have another script that finds all "sweeplinux.txt" files and does an inplace sed to take the 2nd to last string to search for and replaces it with the last string of each line and then passed it to lmcrypt and has the output file the 2nd string in the file.
I am working on something like this now, but am kind of stuck doing the date comparison and erasing the 4 lines of the expired feature.
If you help me figure it out and live in Houston, TX, I will take you to dinner at a steakhouse.
bash sed date
add a comment |
So, I have basically automated a majority of client license expiration reports and license renewals for our clients (I grep files for 31-dec-2018 and then echo the information into a text file that runs on another script to sed the contents based on the strings and runs the old license against lmcrypt and saves it as a new name based on the replacement string)... anywho (enough background info)...
I'd like to create a bash script that will take any files that will grep for a string that is the same in all files that don't run correctly:
(filename):line #:Feature has expired
FLEXlm error: -10,227
For further information, refer to the FLEXlm End User Manual,available at "www.globetrotter.com".
Then find the lines that contain dates that have passed already and remove those sections.
Example:
Today's date would be 14-JAN-2019
License file I am renewing but contains expired features:
SERVER licserver 001122334455
USE_SERVER
VENDOR company
FEATURE Software_F1 company 6.0 1-feb-2019 1 SIGN="0B7A 39A6 41A1
3482 0F3C 304E DFE5 A8C6 B2BC 9DA0 6759 43F6 7D54 4B6A E62B
04F4 1AC5 96BA 138A DD42 48D6 1979 4DF9 7171 ED9B 28A1 D847
21C4 45D0 8D05"
FEATURE Software_F2 company 6.0 31-dec-2018 1 SIGN="115B CDA3 8141
AD9B 6127 59A3 1B71 0D15 5D37 229F F358 031E D5BA 0290 F601
1FC9 A64F 7215 CB54 6CE8 493D 9008 3314 AA8C A0FA 166E E54C
49AC EF93 00E4"
I would like to insert a snippet into the bash script that will remove the FEATURE line and the SIGN code, so that would be 4 lines. So I was thinking find the line number of a date that has past today's date, remove 4 lines, and continue. Maybe an in place sed? And to get even fancier, we keep a notes.txt file and timestamp when we update a license file. I'd like to automatically insert something like this:
notes.txt:
1-JAN-2019 @ 11:33AM:
Modified (filename).lic and removed expired features:
(all lines removed)
Updated date on (filename).lic to (newfilename).lic.
The existing script that scans for 31-dec-2018 is this:
find $1 -type f -not -path '*/__A*' -exec grep -l -i "31-dec-2018" ; > ~/tmpfind.log
rm -rf ~/tmpfileignored.log
cat ~/tmpfind.log | while read line; do
##tempdirname1=`echo $line | sed 's%/[^/]*$%/%'`
tempdirname1=`echo "$line%/*"`
tempfilename1=`echo "$line##*/"`
echo "Directory: $tempdirname1"
echo "Filename: $tempfilename1"
if [ -f "$tempdirname1/sweeplinux.txt" ]
then
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2018/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
else
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2019/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
fi
done
I have another script that finds all "sweeplinux.txt" files and does an inplace sed to take the 2nd to last string to search for and replaces it with the last string of each line and then passed it to lmcrypt and has the output file the 2nd string in the file.
I am working on something like this now, but am kind of stuck doing the date comparison and erasing the 4 lines of the expired feature.
If you help me figure it out and live in Houston, TX, I will take you to dinner at a steakhouse.
bash sed date
So, I have basically automated a majority of client license expiration reports and license renewals for our clients (I grep files for 31-dec-2018 and then echo the information into a text file that runs on another script to sed the contents based on the strings and runs the old license against lmcrypt and saves it as a new name based on the replacement string)... anywho (enough background info)...
I'd like to create a bash script that will take any files that will grep for a string that is the same in all files that don't run correctly:
(filename):line #:Feature has expired
FLEXlm error: -10,227
For further information, refer to the FLEXlm End User Manual,available at "www.globetrotter.com".
Then find the lines that contain dates that have passed already and remove those sections.
Example:
Today's date would be 14-JAN-2019
License file I am renewing but contains expired features:
SERVER licserver 001122334455
USE_SERVER
VENDOR company
FEATURE Software_F1 company 6.0 1-feb-2019 1 SIGN="0B7A 39A6 41A1
3482 0F3C 304E DFE5 A8C6 B2BC 9DA0 6759 43F6 7D54 4B6A E62B
04F4 1AC5 96BA 138A DD42 48D6 1979 4DF9 7171 ED9B 28A1 D847
21C4 45D0 8D05"
FEATURE Software_F2 company 6.0 31-dec-2018 1 SIGN="115B CDA3 8141
AD9B 6127 59A3 1B71 0D15 5D37 229F F358 031E D5BA 0290 F601
1FC9 A64F 7215 CB54 6CE8 493D 9008 3314 AA8C A0FA 166E E54C
49AC EF93 00E4"
I would like to insert a snippet into the bash script that will remove the FEATURE line and the SIGN code, so that would be 4 lines. So I was thinking find the line number of a date that has past today's date, remove 4 lines, and continue. Maybe an in place sed? And to get even fancier, we keep a notes.txt file and timestamp when we update a license file. I'd like to automatically insert something like this:
notes.txt:
1-JAN-2019 @ 11:33AM:
Modified (filename).lic and removed expired features:
(all lines removed)
Updated date on (filename).lic to (newfilename).lic.
The existing script that scans for 31-dec-2018 is this:
find $1 -type f -not -path '*/__A*' -exec grep -l -i "31-dec-2018" ; > ~/tmpfind.log
rm -rf ~/tmpfileignored.log
cat ~/tmpfind.log | while read line; do
##tempdirname1=`echo $line | sed 's%/[^/]*$%/%'`
tempdirname1=`echo "$line%/*"`
tempfilename1=`echo "$line##*/"`
echo "Directory: $tempdirname1"
echo "Filename: $tempfilename1"
if [ -f "$tempdirname1/sweeplinux.txt" ]
then
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2018/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
else
if [[ $tempfilename1 == *perm* ]];
then echo "$tempfilename1 has perm in it - skipping"
else
echo "$tempfilename1 `echo $tempfilename1 | sed 's/2018/2019/g'` 31-dec-2018 31-dec-2019" | tee -a $tempdirname1/sweeplinux.txt
fi
fi
done
I have another script that finds all "sweeplinux.txt" files and does an inplace sed to take the 2nd to last string to search for and replaces it with the last string of each line and then passed it to lmcrypt and has the output file the 2nd string in the file.
I am working on something like this now, but am kind of stuck doing the date comparison and erasing the 4 lines of the expired feature.
If you help me figure it out and live in Houston, TX, I will take you to dinner at a steakhouse.
bash sed date
bash sed date
asked Dec 11 at 20:21
b3ta_nine
61
61
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487443%2fbash-grep-with-date-comparison%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487443%2fbash-grep-with-date-comparison%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown