The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
removing directory in an input file chrysSty UNIX for Dummies Questions & Answers 2 06-04-2008 08:12 PM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 01:34 PM
Adding a character in the beginning of every line in a .dat file Cool Coder Shell Programming and Scripting 2 12-22-2005 03:47 AM
sed not outputting last line of input file 2reperry Shell Programming and Scripting 3 12-16-2005 09:51 AM
perl question - removing line from input file reggiej Shell Programming and Scripting 3 06-07-2005 10:45 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-15-2006
Terrible
Guest
 

Posts: n/a
input a line at the beginning of every file in a directory?

if need to input a word or anything at the beginning of every file in a directory. how do i accomplish this?


say the file is named hyperten. how do i make hyperten the first line of every file in a given directory?

thanks

Last edited by Terrible; 08-15-2006 at 10:59 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 08-15-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 360
cd to the destination directory and execute following script:

Code:
#!/bin/sh

find -maxdepth 1 -type f | while IFS= read vo
do
echo "some_string\
" > .tmp
cat "$vo" >> .tmp
mv .tmp "$vo"
done
Reply With Quote
  #3  
Old 08-16-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
The -maxdepth is not available for all versions of find.
You can also use this more obscure syntax :

Code:
find . \( -type d ! -name . -prune  \) -o  -type f

Jean-Pierre.
Reply With Quote
  #4  
Old 08-16-2006
Terrible
Guest
 

Posts: n/a
when i run that script this is what i get:

find: path-list predicate-list

this is the script i'm running. the line "/var/scripts/scramble" is what i want to put in the beginning of every file in the directory.


#!/bin/sh

find -maxdepth 1 -type f | while IFS= read vo
do
echo "/var/scripts/scramble\
" > .tmp
cat "$vo" >> .tmp
mv .tmp "$vo"
done
Reply With Quote
  #5  
Old 08-16-2006
Terrible
Guest
 

Posts: n/a
sorry guys. i have decided it would be best to add the line to a place other than the first line of the files.

now how do i do that? i need to input that one line script at the beginning of my files, right after the #!/bin/sh line

i thought sed could do this? wrong?
Reply With Quote
  #6  
Old 08-16-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,212
You can use sed (to insert the control/J character noted ^J do Ctrl/V Ctrl/J) :
Code:
#!/bin/sh

find . -maxdepth 1 -type f | \
while IFS= read vo
do
   sed '\_#!/bin/sh_a\^Jsome string' "$vo" > .tmp
   mv .tmp "$vo"
done
Jean-Pierre.
Reply With Quote
  #7  
Old 08-16-2006
Terrible
Guest
 

Posts: n/a
thanks guys
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0