Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
You encapsulate the string in double quotes since white space is the default field separator. You end at PNB since you say what follows that changes.
You pipe into awk and use the -F flag to specify field separator to be "/" rather than white space. The NF is a special variable in awk meaning "number of fields" so $NF is reference to the (last) number. Since your PNB... is preceded by "/" it is a perfect separator to use for what you asked.
Last edited by MensaWater; 08-04-2017 at 09:08 AM.
This command will get the single line from the file and removes anything until "tags/" (including) and returns the remaining line (your version).
If you add the parameter '-i' sed will change the file in place.
This command will get the single line from the file and removes anything until "tags/" (including) and returns the remaining line (your version).
If you add the parameter '-i' sed will change the file in place.
Code:
sed 's/.*tags\///' version.txt -i
This assumes he has no other lines with *tags* on them but is a nice solution.
Grep has "-o" to return only the requested text. See the manpage.
Of course since he says what follows PNB changes he'd have to do something like:
grep -o PNB.......... <filename>
But like the sed solution that assumes no other lines have PNB in them and also assumes that the number of characters following PNB are always the same.
Of course since he says what follows PNB changes he'd have to do something like:
grep -o PNB.......... <filename>
But like the sed solution that assumes no other lines have PNB in them and also assumes that the number of characters following PNB are always the same.
Can you help me on this? people like you help us to save our time.
I would like to learn all this, but I just confuse about the command line "sed"
Thank You all,
how can I write the output of the command into a file as a variable.
for example, how can I wire the following value into a file named "app.version.txt"
version=PNB.X.X.3.015.0
So the "version=" part should be added before the "PNB.X.X.3.015.0"
But like the sed solution that assumes no other lines have PNB in them and also assumes that the number of characters following PNB are always the same.
That's what regex was invented for.
No more fragile than your presumption there are no other lines with both a slash and PNB in a different order.
The `` certainly works but is the old style. Using $() has a couple of advantages:
1) ` is often confused with ' when reading lines so debugging is sometimes a problem.
2) The $() can be nested more easily than the ``.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.