Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
I have these files which have random stuff in them but I want all of them to have "steven" as their very first line. How can I do that to all files with a .txt extension
Distribution: At home: Arch, OpenBSD, Solaris. At work: CentOS, Debian, Ubuntu
Posts: 3,625
Rep:
Linux and Unix systems do not use file extensions the way Windows does -- they don't matter.The following willwork on all text files (though I use *.txt as a fileglob to apply the file operation to all files ending in .txt, but you could use any other expression). The actual command is:
sed -i.bak -e 'i steven\' *.txt
All of the files will be backed up (with a .bak extension added) before they are edited in case something goes wrong. I'd suggest reading up on sed to understand how what I did works.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.