![]() |
|
|
|
|
|||||||
| 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 |
| How to insert text in the middle of a file | kartikkumar84@g | UNIX for Dummies Questions & Answers | 6 | 05-10-2008 11:35 AM |
| insert text in the middle of a file | relle | Shell Programming and Scripting | 3 | 03-13-2008 11:37 AM |
| How to insert text into first line of the file and middle of the file? | ali hussain | Shell Programming and Scripting | 3 | 03-05-2007 01:54 AM |
| insert text into the middle of a original file | mopimp | Shell Programming and Scripting | 1 | 03-26-2006 07:11 AM |
| how to insert and delete characters in the middle of file | ivancheung | High Level Programming | 7 | 10-11-2004 12:08 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 Last edited by boris; 04-13-2007 at 11:43 AM. |
| Forum Sponsor | ||
|
|
|
|||
|
something like this,
to be in the middle Code:
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
|
|
|||
|
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
Quote:
|
|
|||
|
Quote:
Code:
sed "${a}a\\
this is new line" filename
|
|||
| Google The UNIX and Linux Forums |