Shell - Replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell - Replace
# 1  
Old 07-13-2011
Shell - Replace

Hello ,

I am trying to replace a pattern in shell script , basically there is a file with the list of tables like
A.DAT
B.DAT
C.DAT ..

I will need to replace a prefix for the list

TESTA.DAT
TESTB.DAT
TESTC.DAT

Do I need to use <tr> or sed , I am not sure whether I need to use awk to get the print $1 , in my case it's always one string

Thanks,

-
# 2  
Old 07-13-2011
Code:
awk '{ print "TEST" $0 }' < infile > outfile

$0 is a special variable in awk which means 'the entire line'.
# 3  
Old 07-13-2011
Thank you , this helps

If I have to include an variable which is populated in the Run time
like , for e-g

CCode='Google'

awk '{ print "TEST_$CCode" $0 }' < test > test1

Please advice

Thanks
# 4  
Old 07-13-2011
Code:
awk -v VAR="stuff" '{ print VAR $0 }'

# 5  
Old 07-13-2011
Code:
CCode='Google'
sed "s/^/${CCode}/" infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace character in shell scripting

Hi, I need to replace the space " " with underscore "_" using shell scripting. The data are inside the text file. Is there are any simple code to that.? (3 Replies)
Discussion started by: gopishrine
3 Replies

2. Shell Programming and Scripting

Replace with shell variable in awk

Hi, Probably this is a out of scope of the thread. I have a requirement as below I have a file with below content CMD //DS > testfile I have to replace //DS with a value which is assigned to a variable outside using awk gsub. For example var=TEST I expect an output as CMD TEST... (1 Reply)
Discussion started by: Ratheesh Nair
1 Replies

3. Shell Programming and Scripting

Search and replace in shell

I have a server.xml in about 50 instances of JBOSS servers which has the following line <Engine defaultHost="localhost" name="jboss.web"> I need to append something into this line based on the hostname . For example hostname abcdprod40j.corp.abc.net <Engine defaultHost="localhost"... (1 Reply)
Discussion started by: gubbu
1 Replies

4. Shell Programming and Scripting

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 _ com.sun.url=www.sun.com com.ssl.port=808 com.ui.path=/apps/ssi Expected output com.sun.url=_COM.SUN.URL_ com.ssl.port=_COM.SSL.PORT_ com.ui.path=_COM.UI.PATH_ Thanks in... (4 Replies)
Discussion started by: baluchen
4 Replies

5. Shell Programming and Scripting

how to replace a string in the last shell command

for example the last command i run is: tail -f 2010123114_mta2.wmwm.com_postfix-MDAD.log | grep XXXX and i want to raplace '2010123114' with '2010123115', and i don't want to go back to the position and delete 4 and add 5 is there a way to replace a string? like !!//123114/123115 or... (1 Reply)
Discussion started by: wljackhero
1 Replies

6. Shell Programming and Scripting

Shell Script to replace text

I need a little help with a shell script. I want to be able to specify parameters so that the script searches multiple files (specified as parameters) and only modifies the file if it finds the string of text. For the files it doesn't find the string of text within, it should leave it alone. ... (4 Replies)
Discussion started by: joebaber
4 Replies

7. Shell Programming and Scripting

Replace xml values -- Shell --

Hello all, I try to create a bash script but till now without any positiv results. The script should replace different variables in a text file with the right xml values Look at the following xml file: file.xml =================================== <?xml version="1.0"... (14 Replies)
Discussion started by: research3
14 Replies

8. UNIX for Dummies Questions & Answers

replace shell (sh)

Hi, I need to replace the old "sh" binaries with a new binary. what could be the steps for the same. some details: =============== root@mymachine// $ find / -name sh -print /usr/bin/sh /usr/bin/posix/sh /usr/newconfig/etc/mail/cf/sh /var/jail/wp_internet/usr/bin/sh... (6 Replies)
Discussion started by: amit4g
6 Replies

9. 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

10. UNIX for Dummies Questions & Answers

replace a value with another in shell script

hai everybody, i am new to scripting,i have to replace a value with another value ina script...both the values i have got in two seperate variables...can anyone give me the syntax how to do this in a shell script... ie. e1=$5,e2=$6 v2=$1,v3=$7 now i want to... (2 Replies)
Discussion started by: Babu
2 Replies
Login or Register to Ask a Question