Requesting help to replace a string by my bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Requesting help to replace a string by my bash script
# 1  
Old 11-29-2010
Requesting help to replace a string by my bash script

Hello every1,

I need help to replace a string in a file by my bash script.

Find: log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n= %d %5p [%t] (%F:%L) - %m%n

Replace: log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n

I tried by sed, but kept failing when it comes to find/replace special characters, will greatly appreciate if help me to resolve this issue.

Thanks................Sandeep
# 2  
Old 11-29-2010
Code:
$ awk '/log4j/{print $0"%n"}' RS="%n=" file
log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n

Code:
$ sed '/log4j/s/\(.*%n=\).*/\1/g;s/=$//g' file
log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n


Last edited by cabrao; 11-29-2010 at 10:35 AM..
# 3  
Old 11-29-2010
Code:
sed 's/\(log4j.appender.toLogFile.layout.ConversionPattern= %d %5p [%t] (%F:%L) - %m%n\)= %d %5p [%t] (%F:%L) - %m%n/\1/' file

# 4  
Old 11-29-2010
sed solution without using the \( \) \1

Code:
sed '/^log4j/s/=[^=]*$//' infile

# 5  
Old 11-29-2010
Code:
awk -F = '/log4j.appender.toLogFile.layout.ConversionPattern/ {NF=2}1' OFS="=" infile

# 6  
Old 11-30-2010
Thank you very much everyone for these solution........Smilie

Thanks.........Sandeep
# 7  
Old 11-30-2010
Code:
# sed 's/%m%n=.*/%m%n/' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash] - Replace blank and string in csv file

Hi all, i have a .csv file with only two columns, like: Login;Status Luca;S Marco; Stefano; Elettra;S Laura; ... I need to replace the blank space on Status column whit Enabled end, on the same column, S whit Disabled, like: Login;Status Luca;Disabled Marco;Enabled Stefano;Enabled... (10 Replies)
Discussion started by: kamose
10 Replies

2. UNIX for Advanced & Expert Users

BASH Internal : Replace pattern with string without external command

Morning, I'm trying step up my scripting game .. :rolleyes::confused::D Is there a way to do the replacement with an or without using an external command ? I did try but no joy. var=${var//\(|\)/} #!/bin/bash var="lulus.UbiRwidgets.com (10.1.1.1)" var=${var//\(/}... (5 Replies)
Discussion started by: popeye
5 Replies

3. Shell Programming and Scripting

Bash script to replace a character with another

Hi. I'm a complete noob when it comes to scripting. I have approximately 2000 files scattered throughout different locations that I need to rename. The current files have a character, "." , that needs to be replaced with an underscore. I have no clue which route to go about correcting this.... (4 Replies)
Discussion started by: Nvizn
4 Replies

4. Shell Programming and Scripting

Bash script reg-exp , replace , open and write

Hi All I am a new in scripting language and I would like help for you guys I would like to create a file named constant.h and search into all files *.m in specific directory for a reg-exp @"LBL_]+" exp: @"LBL_75847" , and write those matchs to constant.h if there are not written (no... (15 Replies)
Discussion started by: molwiko
15 Replies

5. UNIX for Dummies Questions & Answers

Replace a String using Bash

I'm going freakin crazy here! I've tried multiple attempts and configurationa and cannot get this to work. I have a file: private/etc/apt/sources.list.d/cydia.list I want to replace a string in this file: "deb http:name.of.address ./" with "deb http:name.of.other.address ./" The... (4 Replies)
Discussion started by: thazsar
4 Replies

6. Shell Programming and Scripting

Bash script to accept password and replace characters with * as they are typed

I googled this and couldn't find an answer, so I rolled my own. Here it is, hope it helps. Feel free to improve on it. #!/bin/bash PWORD= ANYKEY=0 echo -n "Password: " until do read -N 1 -s ANYKEY echo -n "*" PWORD="$PWORD$ANYKEY" done echo echo $PWORD exit (3 Replies)
Discussion started by: krisdames
3 Replies

7. Shell Programming and Scripting

Requesting help with shell script

I have been viewing man pages and using google with little luck so far. I am writing a shell script using wbemcli. I can execute the command and get the results I need just fine. ex. wbemcli -nl ein 'http://<username>:<password>@<host>/<targetpc>/root/wmi:MSAcpi_ThermalZoneTemperature' ... (3 Replies)
Discussion started by: Scott Post
3 Replies

8. Shell Programming and Scripting

requesting available port with shell script

how do I request a new and available local port (TCP) to use with shell script? (2 Replies)
Discussion started by: timmylita
2 Replies

9. Shell Programming and Scripting

Script to replace numbers by string

Hi! I need the following script: - All numbers in a filename (0-9) have to be replace by a String ("Zero"-"Nine") - The script has to go through all the files in the current directory and has to replace the numbers as described above... I have no idea how to do this... Thanks! Michael (5 Replies)
Discussion started by: Michi21609
5 Replies

10. Shell Programming and Scripting

Bash string replace

Bash shell. I'm trying to filter a string taken from user input. I can replace one word at a time. This method supports regex, so is it possible to replace various words at a time? STRING="Hello World! word1 word2"; FILTERED=${STRING/word1|word2/}; # Not working: replace 2 or more words ??? ... (10 Replies)
Discussion started by: limmer
10 Replies
Login or Register to Ask a Question