Sponsored Content
Top Forums Shell Programming and Scripting Failed to insert string into file before line Post 79084 by nir_s on Monday 25th of July 2005 10:38:17 AM
Old 07-25-2005
Hi r2007,

I failed in both of the cases.

In the first :
......
Code:
echo "sed ${lineNum}i'\'${sourceString}'\' ${dataSource}" > nir.ksh
/bin/ksh nir.ksh

Code:
platform:/tmp> ./update_data_source.ksh 
+ sourceString=<data-source class="oracle.jdbc.pool.OracleConnectionCacheImpl" name="RiGHTvDS" location="jdbc/RiGHTvociDS" xa-location="jdbc/xa/RiGHTvXADS" ejb-location="jdbc/RiGHTvDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="IAS10G" password="IAS10G" url="jdbc:oracle:thin:@tornado:1521:DB10g" inactivity-timeout="30" max-connections="20" min-connections="20"/>
+ grep -n </data-sources> data-sources.xml
+ awk -F: {print $1}
+ lineNum=30
+ echo sed 30i'\'<data-source class="oracle.jdbc.pool.OracleConnectionCacheImpl" name="RiGHTvDS" location="jdbc/RiGHTvociDS" xa-location="jdbc/xa/RiGHTvXADS" ejb-location="jdbc/RiGHTvDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="IAS10G" password="IAS10G" url="jdbc:oracle:thin:@tornado:1521:DB10g" inactivity-timeout="30" max-connections="20" min-connections="20"/>'\' data-sources.xml
+ > nir.ksh 
+ /bin/ksh nir.ksh
nir.ksh[1]: cannot open data-source: No such file or directory

The second:
......
Code:
echo "sed ${lineNum}i\\${sourceString}\\ ${dataSource}" > nir.ksh
/bin/ksh nir.ksh

Code:
platform:/tmp> ./update_data_source.ksh   
+ sourceString=<data-source class="oracle.jdbc.pool.OracleConnectionCacheImpl" name="RiGHTvDS" location="jdbc/RiGHTvociDS" xa-location="jdbc/xa/RiGHTvXADS" ejb-location="jdbc/RiGHTvDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="IAS10G" password="IAS10G" url="jdbc:oracle:thin:@tornado:1521:DB10g" inactivity-timeout="30" max-connections="20" min-connections="20"/>
+ grep -n </data-sources> data-sources.xml
+ awk -F: {print $1}
+ lineNum=30
+ echo sed 30i\<data-source class="oracle.jdbc.pool.OracleConnectionCacheImpl" name="RiGHTvDS" location="jdbc/RiGHTvociDS" xa-location="jdbc/xa/RiGHTvXADS" ejb-location="jdbc/RiGHTvDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="IAS10G" password="IAS10G" url="jdbc:oracle:thin:@tornado:1521:DB10g" inactivity-timeout="30" max-connections="20" min-connections="20"/>\ data-sources.xml
+ > nir.ksh 
+ /bin/ksh nir.ksh
sed: can't read class=oracle.jdbc.pool.OracleConnectionCacheImpl: No such file or directory
sed: can't read name=RiGHTvDS: No such file or directory
sed: can't read location=jdbc/RiGHTvociDS: No such file or directory
sed: can't read xa-location=jdbc/xa/RiGHTvXADS: No such file or directory
sed: can't read ejb-location=jdbc/RiGHTvDS: No such file or directory
sed: can't read connection-driver=oracle.jdbc.driver.OracleDriver: No such file or directory
sed: can't read username=IAS10G: No such file or directory
sed: can't read password=IAS10G: No such file or directory
sed: can't read url=jdbc:oracle:thin:@tornado:1521:DB10g: No such file or directory
sed: can't read inactivity-timeout=30: No such file or directory
sed: can't read max-connections=20: No such file or directory
sed: can't read min-connections=20/: No such file or directory

Any more suggestions?

Thanks in advance,
Nir
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to insert line break + string in vi (search & replace )

Hello all i have big test file that has allot of structure text something like this : <foo1 *.html> <blah action> somthing 1 somthing 2 </blah> </foo1 > now i will like to insert 2 more lines of text below the <blah action> so it will be like : <foo1... (1 Reply)
Discussion started by: umen
1 Replies

2. Shell Programming and Scripting

search a line and insert string into specific at position

Hi, guys. I have one question: How can I search for a line with certain string in it and then insert a string into this line? For example: There is a file called shadow, the contents of it are below: ************************** ... yuanz:VIRADxMsadfDF/Q:0:0:50:7:::... (9 Replies)
Discussion started by: daikeyang
9 Replies

3. Shell Programming and Scripting

KSH - search for string and insert line above

Hi,, Please excuse my lack of knowledge here. I think I am tring to do something fairly advanced yet am a bit of a beginner..... I want to use a korn shell (as is the norm with others in my company) to write a script to search a file for a string and insert some text above that line. Sudo... (5 Replies)
Discussion started by: HugoDarley
5 Replies

4. Shell Programming and Scripting

How to insert string at particular 4th line in text file

I just want to add a particular string in text file using shell script text file format 1 columns-10 2 text=89 3 no<> 4 5 test-9876 6 size=9 string need to insert in 4th line <switch IP='158.195.2.567' port='5900' user='testc' password='asdfrp' Code='8'> After inserting the... (8 Replies)
Discussion started by: puneet.goel
8 Replies

5. Shell Programming and Scripting

how to insert a string as a first line of the file

Hi I need to update a number of existing files and insert #!/bin/ksh line a the first line of the file. Is there any awk or sed command which would help me to do that instead of doing it manually? Thanks a lot -A (10 Replies)
Discussion started by: aoussenko
10 Replies

6. UNIX for Dummies Questions & Answers

insert string at end of line if it found from list

Hi all, can some one help me out file 1 i have 06/01 3:14 d378299 06/01 8:10 d642036 06/01 10:51 d600441 06/01 10:52 d600441 06/01 11:11 d607339 06/01 11:49 d398706 something like this and in file named list i have ( there is space btwn 06/01 and 11:49 and d398706) d607339... (5 Replies)
Discussion started by: zozoo
5 Replies

7. Shell Programming and Scripting

Awk, if line after string does not match insert

I have a large file with interface records. I need to check every record that has the string "encapsulation bridge1483" and if the next line after this does not have "ip description" then I need to insert a line to add "ip description blah_blah_blah. Sample file: interface atm 1/0.190158... (3 Replies)
Discussion started by: numele
3 Replies

8. Shell Programming and Scripting

Insert String every n lines, resetting line counter at desired string

I need to read a text file and insert a string every n lines, but also have the line counter restart when I come across a header string. Line repeating working every 3 lines using code: sed '0~3 s/$/\nINSERT/g' < INPUT/PATH/FILE_NAME.txt > OUTPUT/PATH/FILE_NAME.txt I cannot seem to find... (1 Reply)
Discussion started by: Skonectthedots
1 Replies

9. Shell Programming and Scripting

Insert line based on found string

Hi All I'm trying to insert a new line at the before each comment line in a file. Comment lines start with '#-----' there are other comments with in lines but I don't want a new line there. Example file: blah blah #do not insert here #this is a comment blah #some more #another comment... (10 Replies)
Discussion started by: Mudshark
10 Replies

10. Shell Programming and Scripting

Insert a user input string after matched string in file

i am having file like this #!/bin/bash read -p 'Username: ' uservar match='<color="red" />' text='this is only a test so please be patient <color="red" />' echo "$text" | sed "s/$match/&$uservar\g" so desireble output what i want is if user type MARIA this is only a test so please... (13 Replies)
Discussion started by: tomislav91
13 Replies
All times are GMT -4. The time now is 04:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy