Substitue single-digit, two-digit, and 3-digit numbers with text using sed
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Substitue single-digit, two-digit, and 3-digit numbers with text using sed
Hi,
I'm trying to write a sed script that will evaluate a file with exit codes, and substitutes the numerical exit codes (which are single-, two-, or three-digit numbers) for their description.
The process goes like this:
I have a script that obtains an exit code/status for backups and dumps the output in a file. We'll call the file bkp_status. Entriess in bkp_status are in this format:
I have tried for a couple days now to pipe this file into a sed script that will substitute the exit_code for its description, and generate output as follows:
SED has no capacity to evaluate numbers---it works strictly on strings. Before you start piping commands together, test them one at a time to make sure they are doing what you need.
The first three posts were really how I meant them, I thought they were sort of separate ... sorry about that.
Only the fourth one I added to draw more attention to the fact that I left out the //'s, just in case they maybe saw it quickly and tried it and had it do the wrong thing.
That's basically what I just posted, ghostdog, only shorter. It would be better for space. I also wrote in my post "something like:" because I know it can be made with fewer lines, and maybe something else could come up that the original poster wants to do.
Thanks Berhanie, joeBuffer, and ghostdog74 for your posts!! VERY much appreciated. I will test them later tonight and report back with my findings.
pixellany, thanks for the link to grymoire.com. I've referenced it many times before for reminders here-and-there; it's one of the more popular and better-written tutorials on the Web. And FYI, I'm at the part in my script where the pipe didn't work, so I came here for assistance. As a moderator, and somewhat of a forum role-model, you should take care with your tone and suggestions. It may not be what you intended, but your post comes across like you're advising someone who has no clue what they're doing; such a post can be discouraging when it's directed toward someone who doesn't or offensive when it's directed toward someone who does.
Thanks Berhanie, joeBuffer, and ghostdog74 for your posts!! VERY much appreciated. I will test them later tonight and report back with my findings.
pixellany, thanks for the link to grymoire.com. I've referenced it many times before for reminders here-and-there; it's one of the more popular and better-written tutorials on the Web. And FYI, I'm at the part in my script where the pipe didn't work, so I came here for assistance. As a moderator, and somewhat of a forum role-model, you should take care with your tone and suggestions. It may not be what you intended, but your post comes across like you're advising someone who has no clue what they're doing; such a post can be discouraging when it's directed toward someone who doesn't or offensive when it's directed toward someone who does.
Thanks again everyone!
~D
I am sorry, but my comments were:
1) a matter of fact statement about how SED does not evaluate numbers, and
2) a suggestion on how to unravel what was being attempted.
If you stick around here for a while, you'll note that many members have time available only in fragments-----you'll quite often see a terse suggestion or comment with more in-depth follow-up later.
Regardless, I'm glad to see you are getting somewhere and that you have the courtesy to thank those that help you.
s/,\<6\>/,6,(the backup failed to back up the requested files)/
s/,\<8\>/,8,(unable to determine the status of rbak)/
s/,\<86\>/,86,(media position error)/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.