![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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? |
|
#6
|
||||
|
||||
|
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 |
|
#7
|
|||
|
|||
|
thanks guys
|
|||
| Google The UNIX and Linux Forums |