Visit Our UNIX and Linux User Community


insertion of text from sed script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting insertion of text from sed script
# 1  
Old 05-25-2009
Java insertion of text from sed script

Hi ,

This is my first thread ; facing some issues withmy sed script

I need to insert the code from my log file which is between two keywords.

content is like this ........
log
############################

log1 log2
231 "Ban" "tom" and the line one of the cross line
friend samsung and the "unit" lite three two four
log3 log4

I used this sed script

sed -n '/log1 log2/,/log3 log4/p' log > file1

It is printing the whole content including log1 log2 and log3 log4 which I dont want in the file1

Please give me some advice in this regards

Shalini
# 2  
Old 05-25-2009
not an elegant way, here is a try

Code:
awk '{ if ( $0 ~ /log1 log2/ ) { set=1; next }; if ( $0 ~ /log3 log4/ ) { set = 0 }; if ( set ) { print } }' sample

# 3  
Old 05-25-2009
Try this

awk ' /log1 log2/,/log3 log4/ ' log > file1

or here is another code

awk '/log1 log2/,/log3 log4/ {gsub(/log1 log2/, log3 log4); print}' log > file1

or here is another code

awk '/log1 log2/,/log3 log4/ {gsub(/log1 log2/, log3 log4); print}' log > file1

Previous Thread | Next Thread
Test Your Knowledge in Computers #335
Difficulty: Easy
Linus Torrent is the creator of the Linux kernel, which went on to be used in Linux, Android, and Chrome OS.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX shell script for matrix insertion into a file

I have a script which is extracting data from a database in an excel file in below given format, date_time calling_app1 count of requests date calling_app x 34 date calling_app y 1034 I want to write a script which will write data into a file like this ... (3 Replies)
Discussion started by: TNT47
3 Replies

2. Shell Programming and Scripting

Text manipulation with sed/awk in a bash script

Guys, I have a variable in a script that I want to transform to into something else Im hoping you guys can help. It doesn't have to use sed/awk but I figured these would be the simplest. DATE=20160120 I'd like to transform $DATE into "01-20-16" and move it into a new variable called... (8 Replies)
Discussion started by: dendenyc
8 Replies

3. Shell Programming and Scripting

Awk/sed problem to write Db insertion statement

Hi There, I am trying to load data from a csv file into a DB during our DB migration phase. I am successfully able export all data into a .csv file but those have to rewritten in terms insert statement which will allow for further population of same data in different DB My exiting csv record... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

4. Shell Programming and Scripting

Text file insertion via sed

I have 800+ html files that need to have a javascript added to them in the head. I can do the looping, setting filenames as variables, etc. but I cannot figure out how to insert my javascript file into the html. My javascript is in a file named jsinsert.txt It basically has this format:... (4 Replies)
Discussion started by: Trapper
4 Replies

5. Shell Programming and Scripting

Need help in using sed/awk for line insertion in xml

Hello, I have two text files (txt1 and txt2). txt1 contains many lines with a single number in each line. txt2 (xml format) contains information about the numbers given in txt1. I need to insert one line in txt2 within the scope of each number taken from txt1. Sample problem: txt1: 12 23... (1 Reply)
Discussion started by: shekhar2010us
1 Replies

6. Shell Programming and Scripting

AWK script problem insertion of code

Hi , I am having two files like this FILE1 #################### input SI_TESTONLY_R_00; input CE0_SE_INPUT_TESTONLY; input CE0_TCLK_TESTONLY; input SI_JTGCLOCKDR_JTAG_R_00; input CE0_TCLK_JTGCLOCKDR_JTAG; input CE0_SE_INPUT_JTGCLOCKDR_JTAG; output SO_TESTONLY_R_00; output... (2 Replies)
Discussion started by: jaita
2 Replies

7. Shell Programming and Scripting

Insertion New line whilst reading the text file

Hi, For the text file let us say t.txt having the statements as below. filename : t.txt. Contents : This is first string1 This is first string2 This is first string3 The output of the file should have newline. How to introduce the new line so that the output be as follows ... (5 Replies)
Discussion started by: krackjack
5 Replies

8. Shell Programming and Scripting

Sed or awk script to remove text / or perform calculations from large CSV files

I have a large CSV files (e.g. 2 million records) and am hoping to do one of two things. I have been trying to use awk and sed but am a newbie and can't figure out how to get it to work. Any help you could offer would be greatly appreciated - I'm stuck trying to remove the colon and wildcards in... (6 Replies)
Discussion started by: metronomadic
6 Replies

9. Shell Programming and Scripting

Simple 'sed' script for replacing text

Hi All, So I found a simple sed command to replace text in a file (http://www.labnol.org/internet/design/wordpress-unix-replace-text-multiple-files/1128/): sed -e 's/OLDtext/NEWtext/' -i file(s) Because I'm lazy and don't want to remember this each time I want to do this, I wrote the following... (4 Replies)
Discussion started by: ScKaSx
4 Replies

10. Shell Programming and Scripting

Need to insert new text and change existing text in a file using SED

Hi all, I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output. sed '$a\ hi... ' shell > shell1 But I face problem when using the same in script. It is throwing the error as, sed: command garbled:... (4 Replies)
Discussion started by: iamgeethuj
4 Replies

Featured Tech Videos