Find and Replace in Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and Replace in Shell script
# 1  
Old 05-23-2013
Find and Replace in Shell script

Friends,

I have more than 1000 lines in text file which needs to be converted as UPPERCASE by adding _

Code:
com.sun.url=www.sun.com
com.ssl.port=808
com.ui.path=/apps/ssi

Expected output

Code:
com.sun.url=_COM.SUN.URL_
com.ssl.port=_COM.SSL.PORT_
com.ui.path=_COM.UI.PATH_

Thanks in advance
Bala
# 2  
Old 05-23-2013
Can you show us what have you tried so far?
# 3  
Old 05-23-2013
I hope this will be useful for you:
Code:
awk -F'=' '{printf "%s=_%s_\n",$1,toupper($1)}' file_to_convert.txt

# 4  
Old 05-24-2013
Quote:
Originally Posted by franzpizzo
I hope this will be useful for you:
Code:
awk -F'=' '{printf "%s=_%s_\n",$1,toupper($1)}' file_to_convert.txt

This command is working fine thanx, but the white space also replaced by =__

How can we add the condition to this..Smilie
# 5  
Old 05-24-2013
Ensure there is a = character (2 fields)
Code:
awk -F'=' 'NF>1 {printf "%s=_%s_\n",$1,toupper($1)}'

Ensure there is a = and no #
Code:
awk -F'=' '/^[^#]+=/ {printf "%s=_%s_\n",$1,toupper($1)}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script @ Find a key word and If the key word matches then replace next 7 lines only

Hi All, I have a XML file which is looks like as below. <<please see the attachment >> <?xml version="1.0" encoding="UTF-8"?> <esites> <esite> <name>XXX.com</name> <storeId>10001</storeId> <module> ... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies

2. Shell Programming and Scripting

Shell Script to find common lines and replace next line

I want to find common line in two files and replace the next line of first file with the next line of second file. (sed,awk,perl,bash any solution is welcomed ) Case Ignored. Multiple Occurrence of same line. File 1: hgacdavd sndm,ACNMSDC msgid "Rome" msgstr "" kgcksdcgfkdsb... (4 Replies)
Discussion started by: madira
4 Replies

3. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

4. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

5. Shell Programming and Scripting

shell script to find and replace a line using a identifier

Hi all im having trouble starting with a shell script, i hope someone here can help me i have 2 files file1: 404905.jpg 516167 404906.jpg 516168 404917.psd 516183 404947.pdf 516250 file2: 516250 /tmp/RecyclePoster18241.pdf 516167 /tmp/ReunionCardFINAL.jpg 516168... (7 Replies)
Discussion started by: kenray
7 Replies

6. UNIX for Dummies Questions & Answers

Find and replace in all files using shell scripting

Hi all, I'm looking to find and replace a string in all HTML files within a certain directory, including subdirectories. Normally, I would play with this a little to get it to work, but I can't mess this up, so I'm going to ask here. Basically, I want to find "<title>" in all *.htm* files... (11 Replies)
Discussion started by: slothario
11 Replies

7. Shell Programming and Scripting

shell script to find and replace string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (11 Replies)
Discussion started by: pharos467
11 Replies

8. Shell Programming and Scripting

Find and Replace in multiple files (Shell script)

hi guys, Suppose you have 100 files in a folder and you want to replace all occurances of a word say "ABCD" in those files with "DCBA", how would you do it ??? jatin (13 Replies)
Discussion started by: jatins_s
13 Replies

9. Shell Programming and Scripting

Find and replace a part of the word in Shell

I have a csv file in which there are numbers like 078976/9XXX 098754/8XXX I want to replace the XXX with null. I want to know the command/code to do this. I know how to replace the whole word/number. But don't know how to replace a part of it. Thanks in advance, Mihir (3 Replies)
Discussion started by: mihirk
3 Replies

10. UNIX for Advanced & Expert Users

find a shell and replace the line

I need a shell which makes a search of an UNIX script and them modifies. :confused: vi $(grep -l 5 $(find . -name 'vellon.bcf' -print)) (1 Reply)
Discussion started by: jvellon
1 Replies
Login or Register to Ask a Question