The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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 02:35 PM
insert text in the middle of a file relle Shell Programming and Scripting 3 03-13-2008 03:37 PM
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 05:54 AM
insert text into the middle of a original file mopimp Shell Programming and Scripting 1 03-26-2006 10:11 AM
how to insert and delete characters in the middle of file ivancheung High Level Programming 7 10-11-2004 03:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-11-2007
boris boris is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 6
Angry

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 02:43 PM..
  #2 (permalink)  
Old 04-11-2007
matrixmadhan matrixmadhan is online now Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
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
  #3 (permalink)  
Old 04-12-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 564
Try this

Code:
a=$((`wc -l < filename` / 2))
sed ''$a' a this is new line' filename
  #4 (permalink)  
Old 04-12-2007
boris boris is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 6
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:
Originally Posted by jacoden
Try this

Code:
a=$((`wc -l < filename` / 2))
sed ''$a' a this is new line' filename
  #5 (permalink)  
Old 04-13-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Quote:
Originally Posted by boris
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
Code:
sed "${a}a\\
this is new line" filename
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0