Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
I'm writing a shell script that uses cat to combine a bunch of csv files into one. What I'm trying to do is extract a 16 digit number with a known prefix out of each line and display that only. I've got it using grep to display only the lines with the number but how would you suggest extracting/displaying just the number from the string? I'm sure it could/should be done with awk or sed but I'm relatively knew to the commands and I'm horrible at regex.
If the pattern you pass to grep matches just the part of the line you are interested in, you can use the -o option to the GNU grep to output just that part of the matching lines.
If not, there are a multitude of ways to extract parts of a line. cut, awk, sed, perl. Which is best depends on the nature of the problem, your platform and personal preference. If you describe in more detail what you are trying to do (i.e. include example input, output and metrics such as data set size), I'm happy to make a suggestion.
Distribution: Fedora 10[Cambridge] and Ubuntu 9.04[Jaunty]
Posts: 201
Rep:
a more detailed explanation of ur prob ll put more light on how to attack the problem...but as matthew rightly suggested u can make use of simple comands like cut...keep life simple...i'll do teh job...but again it all depends on ur requirement...so if u r still stuck with the prob...state ur problem more clearly...
If the pattern you pass to grep matches just the part of the line you are interested in, you can use the -o option to the GNU grep to output just that part of the matching lines.
If not, there are a multitude of ways to extract parts of a line. cut, awk, sed, perl. Which is best depends on the nature of the problem, your platform and personal preference. If you describe in more detail what you are trying to do (i.e. include example input, output and metrics such as data set size), I'm happy to make a suggestion.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.