Results 1 to 5 of 5
Hi ...
I am having a lot of .c files in my current directory. Now i have add some comments to the starting of all files like Name, Author, copyright, ...
- 12-10-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 49
help required in scripting
Hi ...
I am having a lot of .c files in my current directory. Now i have add some comments to the starting of all files like Name, Author, copyright, etc...
So instead of editing each file, i am planning to write a shell script. Can anybody help me in that.
- 12-10-2008 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
You could use something like
Code:sed -i '1i\my text goes here' *.c
- 12-10-2008 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 49
Hi...
i gave
sed -i 'li\Name:raja' *.c
but i am getting error like this.
# sed: -e expression #1, char 2: extra characters after command
- 12-10-2008 #4Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
That should be a "1" (one), not an "l" (ell) inHowever, to insert a number of lines, perhaps a "read" would be more suitable:Code:'li\Name:raja'
Producing:Code:#!/bin/bash - # @(#) s4 Demonstrate insertion of file after line number. echo echo "(Versions displayed with local utility \"version\")" version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) sed set -o nounset echo echo " Main data file file1:" cat file1 echo echo " File of text to be inserted at line 1:" cat file2 echo echo " Results, sed insert after line 1 (one):" sed "1r file2" file1 exit 0
The sed command is not trivial to learn (especially from the man page), but can be very useful once you get used to it. See a tutorial like: Sed - An Introduction and Tutorial to get started learning ... cheers, drlCode:% ./s4 (Versions displayed with local utility "version") Linux 2.6.11-x1 GNU bash 2.05b.0 GNU sed version 4.1.2 Main data file file1: one two three four File of text to be inserted at line 1: first second third fourth fifth Results, sed insert after line 1 (one): one first second third fourth fifth two three fourWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 12-10-2008 #5Just Joined!
- Join Date
- Aug 2008
- Posts
- 49
Hi...
Thanks...


Reply With Quote