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 > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Insert a line in a text file 4scriptmoni Shell Programming and Scripting 10 08-04-2008 10:17 AM
Insert line into file vinay123 Shell Programming and Scripting 3 07-01-2008 03:07 AM
Insert text file at a certain line. insania Shell Programming and Scripting 4 08-01-2006 02:46 AM
insert a line in a file RishiPahuja Shell Programming and Scripting 7 06-22-2005 03:47 AM
Insert a line as the first line into a very huge file shriek UNIX for Advanced & Expert Users 3 03-09-2005 01:22 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 10-13-2008
tarunicon's Avatar
tarunicon tarunicon is offline
Registered User
  
 

Join Date: Oct 2008
Location: INDIA
Posts: 25
help with insert line into file

hi..i wanted to know is there any way to take input from the user and copy that a particular line number in a particular file

for eg . i wanted to create acl in squid at line number 2400 in squid.conf file
so the user gives an input like acl inetblock src 192.168.0.0/255.255.0.0

so is there any way i can append this line to line number 2400
will i have to use awk or sed or regex ..i dont know what to use ..

i am a noob in linux so was looking for help
  #2 (permalink)  
Old 10-13-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,300
Play around with something like:

Code:
#!bin/sh

read -p "Give your input: " resp

awk -v var=$resp 'NR==2400{print var}{print}' file > new_file
Regards
  #3 (permalink)  
Old 10-13-2008
tarunicon's Avatar
tarunicon tarunicon is offline
Registered User
  
 

Join Date: Oct 2008
Location: INDIA
Posts: 25
re:help

i named the script squid.sh and this is what the output was


[userX@server1 ~]# ./squid.sh
Give your input: acl squid test dstdomain yahoo.com
awk: cmd. line:1: fatal: cannot open file `test' for reading (No such file or directory)
  #4 (permalink)  
Old 10-13-2008
tarunicon's Avatar
tarunicon tarunicon is offline
Registered User
  
 

Join Date: Oct 2008
Location: INDIA
Posts: 25
re:help

i couldnt understand what the error was here ...
  #5 (permalink)  
Old 10-13-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,300
Quote the variable:

Code:
awk -v var="$resp" 'NR==2400{print var}{print}' file > new_file
Regards
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 05:19 PM.


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