Shell scripting substitution techniques


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripting substitution techniques
# 1  
Old 09-23-2010
Shell scripting substitution techniques

Hi guys, I'm looking for some thoughts on this. I'm trying to do a clean 1 liner to substitute some values. What I have:

Code:
sed 's/Personid=.*/Personid=xxxxxx/' $tmpFileOut

Code:
sed 's/Person:.*/Person:xxxxxx/' $tmpFileOut

Code:
sed 's/PersonID:.*/PersonID: xxxxxx/' $tmpFileOut

Obviously that's a bit sucky, I'm repeating 3 lines which are all basically doing the same thing. I want to smarten it up. The thing they all have in common is that I'm looking for 'Person' and whatever is after that, and substituting it. Is there a cleaner way to do the above in one go?

Perl - I'm doing a substitution like this:

Code:
perl -pe 's/(?<![a-z])dog(?![a-z])/cat/g' $tmpFileOut

Code:
perl -pe 's/(?<![a-z])green(?![a-z])/blue/g' $tmpFileOut

again, I'm repeating lines - what's a cleaner way to do this in perl? I have like 15 lines of substitions, I'd like it short and sweet - what's the best way to do it? Put all substitions onto one line? how would I do that? or would some kind of array be the best way to do it?

Help/thoughts appreciated Smilie

Last edited by rich@ardz; 09-23-2010 at 05:01 PM.. Reason: code tags
# 2  
Old 09-23-2010
Code:
sed 's/\(Person\(id=\|:\|ID:\)\).*/\1XXXXXX/' infile

For second question,you need provide some sample inputs and expect output first.

Last edited by rdcwayx; 09-23-2010 at 05:46 PM..
This User Gave Thanks to rdcwayx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Escape and command substitution in scripting

I have one question in shell script for escape "\" with command substitution "` `". I post there to seek help to understand how it works. My original one piece of code in script like this: This piece of code in whole script is working without errors chk_mode=`sqlplus -s /nolog<<EOF connect /... (4 Replies)
Discussion started by: duke0001
4 Replies

2. Shell Programming and Scripting

Help with substitution in shell script

Hello, I Have a file like this, with five columns: B D F T L --------- 0 0 0 0 0 0 0 0 1 0 0 2 0 0 1 I need, for each row, to append another five columns similar to the first ones, but with the field labeled as "T" (4th field of the column) substituted in this way: (16 * value of... (3 Replies)
Discussion started by: PapaJustify
3 Replies

3. Shell Programming and Scripting

Using C-Shell Scripting for Substitution

mv myFile.txt myFile.txt.bak sed s/foo/bar/g myFile.txt.bak > myFile.txt Turn the two-line version, above, of the substitution commands into a shell script, subst1 taking three parameters: the string to be replaced the string with which to replace it the name of the file in which to make the... (1 Reply)
Discussion started by: RogerW
1 Replies

4. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

5. Solaris

Shell variables substitution in a file

Hi, I have to read a file and translate the contents including substituting the variables if any and write to another file without using sed or awk. For ex:- inputfile.txt ----------- servername=$SERVER application=$APPL outputfile.txt ------------ servername=actual server name... (2 Replies)
Discussion started by: axes
2 Replies

6. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question