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.
Hi,
I don't pretend anyone to do my work, but I am wondering which would be the best way to insert a row into a sorted text file, if the first field changes:
Is this by any chance homework? It looks like it is. Anyway, have a look at this Sed tutorial, it can be used to do what you need, amongst other tools. LQ users are at their best solving problems but are not in the habit of, like you saying do the work for you. So post what you've tried and we'll take it from there. Enjoy the forums and Linux.
Could you provide some actual lines of input and desired output, instead of an idea. Using sed and awk the description needs to exact. For example, is the first column always 5 characters in width? If not, I would have had to convert the commas to spaces or tabs for the uniq command to process just the first column.
You could use `uniq' to select changes in the first column. Pipe the results to sed to 1) delete the first line 2) generate a sed script with lines of the form:
/22222,aaaa,bbbb/i\
inserted line
/33333,abcd,defg/i\
inserted line
Then to perform the conversion run the sed script: sed -f inserts.sed input.tex >output.tex
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.