i want to add a string in a very top of a file without using VI or SED or AWK
this is what ive done:
(echo '0a'; echo 'LINE OF TEXT'; echo '.'; echo 'wq') | ed -s myfile
to add astrng right in the middle i could have count the lines of the file and just chenge the address.
EG. if file has 6 lines of text:
(echo '3a'; etc...etc...etc...)
Is there a method to do it where i do not need to know how many lines has a file, the script would add it straight in the middle?
aigles
2
lines=`wc -l < myfile.txt`
half=`expr $lines / 2`
(echo "${half}a"; echo 'LINE OF TEXT'; echo '.'; echo 'wq') | ed -s myfile
thnx a lot m8 u great!
look what im trying to do:
#!bin/bash
file=$1
read myVar
(echo '0a'; echo '$myVar'; echo '.'; echo 'wq') | ed -s $1
i want to create a script which always put a string at the very top.
but why when i run it instead of displaying a tex the output is $myVar
eg:
$myVar
mmmm....
Hi everybody!!!!
seems to me
anbu23
4
Remove the quotes
(echo '0a'; echo $myVar; echo '.'; echo 'wq') | ed -s
$1
Kool its true!!!!!!
and look at this now please...
file=$1
lines=$(wc -l < $1)
half=expr $lines / 2
(echo "${half}a"; echo '8888'; echo '.'; echo 'wq') | ed -s $1
why its not writing the string 888 in the middle of the file?
aigles
6
file=$1
lines=$(wc -l < $1)
half=$(expr $lines / 2)
(echo "${half}a"; echo '8888'; echo '.'; echo 'wq') | ed -s $1
thnx a lot it works perfectly!!!!!