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
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
cd to the destination directory and execute following script:
#!/bin/sh
find -maxdepth 1 -type f | while IFS= read vo
do
echo "some_string\
" > .tmp
cat "$vo" >> .tmp
mv .tmp "$vo"
done
The -maxdepth is not available for all versions of find.
You can also use this more obscure syntax :
find . \( -type d ! -name . -prune \) -o -type f
Jean-Pierre.
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
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?
You can use sed (to insert the control/J character noted ^J do Ctrl/V Ctrl/J) :
#!/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.
thanks guys