boris
1
I wrote a script like
#!/bin/bash
echo $1 > temp
cat $2 >> temp
mv temp $2
now I have problem appending the above script(only using bash shell) so that it now inserts the first argument into the middle of the file.
I have tried using $(('wc -l < file' / 2 ))
but invain so could any one help.
Reply With Quote
something like this,
to be in the middle
a=$((`wc -l < filename` / 2))
awk -v var=$a '{ if( NR == var) { print "newline to be added"; print } else { print } }' filename > newf
mv newf filename
Try this
a=$((`wc -l < filename` / 2))
sed ''$a' a this is new line' filename
boris
4
when I insert this command and run the sript it give a message stating Syntax error.....is there any other command like head or tail command
anbu23
5
sed "${a}a\\
this is new line" filename