Nov 23, 2004 #1 stu78 Programmer May 29, 2002 121 GB Hi, I am writing a sed script to perform a task. However, one of the lines I want to modify has 2 matches in the file. How can I specify I only want to modify the second occurance?
Hi, I am writing a sed script to perform a task. However, one of the lines I want to modify has 2 matches in the file. How can I specify I only want to modify the second occurance?
Nov 23, 2004 #2 PHV MIS Nov 8, 2002 53,708 FR Can you please post your current sed script ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
Can you please post your current sed script ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Nov 23, 2004 Thread starter #3 stu78 Programmer May 29, 2002 121 GB Yes; sed '/^RolloverSize=/s/0xa;/0x64;/' registry> tmp && mv tmp registry The registy file has two enties; RolloverSize= 0x64; REG_DWORD TraceConfig= ; REG_SZ RolloverSize= 0x64; REG_DWORD I want to target the second instance only. Upvote 0 Downvote
Yes; sed '/^RolloverSize=/s/0xa;/0x64;/' registry> tmp && mv tmp registry The registy file has two enties; RolloverSize= 0x64; REG_DWORD TraceConfig= ; REG_SZ RolloverSize= 0x64; REG_DWORD I want to target the second instance only.
Nov 23, 2004 #4 PHV MIS Nov 8, 2002 53,708 FR You may try something like this: awk ' {b=$0} /^RolloverSize/{++i;if(i==2)sub(/0xa;/,"0x64",b} {print b} ' registry> tmp && mv tmp registry Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
You may try something like this: awk ' {b=$0} /^RolloverSize/{++i;if(i==2)sub(/0xa;/,"0x64",b} {print b} ' registry> tmp && mv tmp registry Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Nov 23, 2004 Thread starter #5 stu78 Programmer May 29, 2002 121 GB Can I not just use a line parameter within SED? Like the g for global parameter? Upvote 0 Downvote
Nov 24, 2004 Thread starter #6 stu78 Programmer May 29, 2002 121 GB HI PH. This file does not work for me... Any more suggestions? Upvote 0 Downvote
Nov 24, 2004 #7 Ygor Programmer Feb 21, 2003 623 GB Try ... awk '/^RolloverSize=/&&c++{sub("0xa;","0x64;")};1' registry> tmp && mv tmp registry Upvote 0 Downvote
Nov 24, 2004 #8 PHV MIS Nov 8, 2002 53,708 FR This file does not work for me Can you please be more descriptive ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
This file does not work for me Can you please be more descriptive ? Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
Nov 25, 2004 Thread starter #9 stu78 Programmer May 29, 2002 121 GB Hi PH, THis is the error; $ ./test.sh awk: cmd. line:3: /^RolloverSize/{++i;if(i==2)sub(/0xa;/,"0x64",b} awk: cmd. line:3: ^ syntax error Stu Upvote 0 Downvote
Hi PH, THis is the error; $ ./test.sh awk: cmd. line:3: /^RolloverSize/{++i;if(i==2)sub(/0xa;/,"0x64",b} awk: cmd. line:3: ^ syntax error Stu
Nov 25, 2004 #10 PHV MIS Nov 8, 2002 53,708 FR OK, you may try this: awk ' {b=$0} /^RolloverSize/{++i;if(i==2)sub("0xa;","0x64;",b)} {print b} ' registry> tmp && mv tmp registry Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244 Upvote 0 Downvote
OK, you may try this: awk ' {b=$0} /^RolloverSize/{++i;if(i==2)sub("0xa;","0x64;",b)} {print b} ' registry> tmp && mv tmp registry Hope This Helps, PH. Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244