batch append string to the end of a determined line in text files
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.
i run in to this problem a lot to. im not sure what the clean way to do it is, but an ugly fix is to:
#! /bin/bash
for X in *.txt
do
sed -e '1/1s/$/.php/1' $X > tmp
mv tmp $X
done
you only want to use one '>' so it will overwrite tmp everytime instead of appending to it.
Tinkster,
#!/bin/bash
for X in *.txt
do
sed -e '1/1s/$/.php/1i' $X > $X
done
emptied the output *.txt files. Does w for write prevent this?
sirclif, the tmp trick works as expected . When i tested it, it took some time to move all the huge files. I guess that mv parses all the file length or the memory reads through all over again. I wonder if there is a way of making the bash edit the first line and go.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.