![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need solution concatenate and display 2 lines as 1 with a condition for 2 line ? | vithala | UNIX for Advanced & Expert Users | 1 | 07-10-2008 02:27 PM |
| Linux shell Script not null checking IF condition | kaushys | UNIX for Dummies Questions & Answers | 3 | 07-02-2008 06:54 AM |
| Is There a Sed Solution for This? | racbern | Shell Programming and Scripting | 1 | 03-13-2008 11:31 AM |
| Checking condition inside the loop | ithirak17 | Shell Programming and Scripting | 1 | 03-13-2008 08:37 AM |
| Condition checking | trynew | Shell Programming and Scripting | 14 | 06-21-2002 12:41 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
sed solution for condition checking
Hi all , Recently i came across this in FAQ's. I have a file Code:
cat rem.txt sreedhar 20 sreedhar 10 sreedhar 15 sreedhar 18 sreedhar 16 sreedhar 30 I have to replace sreedhar with "Sridhar" if the second parameter is > 18. I need to do it in "sed" only. I am wondering how this can be done. |
|
||||
|
Thanks zaxxon for the solution. But it's not working as i am getting the error Code:
Function / 19$/ { s/sreedhar/Sridhar/ } cannot be parsed.
Yes , i worked with awk and it's easy to do it in awk. But sed's solution is seems to be cumbersome as we are not doing much like arithmetic operations. Last edited by panyam; 07-21-2009 at 10:13 AM.. |
|
||||
|
With a little modification to above script, you can do this... Code:
sed -n '
/ 19$/ {
s/sreedhar/Sridhar/
p
}
/ [2-9][0-9]$/ {
s/sreedhar/Sridhar/
p
}' file
---------- Post updated at 07:02 PM ---------- Previous update was at 07:00 PM ---------- If the number is negative or greater than 99... We need to tweak a bit more. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|