![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help needed please. | jerryboy78 | UNIX for Dummies Questions & Answers | 3 | 03-16-2008 10:06 AM |
| help needed | nnayagam | Shell Programming and Scripting | 2 | 03-07-2008 02:34 AM |
| Little help needed. | Netghost | AIX | 5 | 08-10-2006 11:29 AM |
| Help needed | dsravan | Shell Programming and Scripting | 2 | 07-20-2006 06:37 AM |
| awk help needed. | cskumar | Shell Programming and Scripting | 0 | 07-20-2006 04:24 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Could someone tell me how to replace varibles using SED inside Korn Shell?
e.g. I have a ksh file program.ksh below: ------------------------------------ #!/bin/ksh sed -n '/ABC/p' $1 > output.txt if [[ $2 = AAA ]] then status=new elif [[ $2 = BBB ]] then status=old fi sed -n '/$status/p' $1 >> output.txt ------------------------------------ I have a text file called filename.txt with the contents below: ------------------------------------ DDD old CCC new ABC old ------------------------------------ When I run program.ksh with filename.txt and BBB as input I want output.txt to contain the two lines below but with the current program it only outputs "ABC new". DDD old ABC new I guess $status is not being recognized as a varible but how do I get this work? I tried putting "\" in front of $status but it didn't work. Any help will be greatly appreciated. Last edited by stevefox; 12-01-2005 at 11:42 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
i wonder how you would be arriving at
DDD old ABC new <-- this line there is no such file entry as ABC new > cat filename.txt DDD old CCC new ABC old here's the modification Code:
> cat program.ksh #!/bin/ksh sed -n '/ABC/p' $1 > output.txt # ABC old if [[ $2 = AAA ]] then status=new elif [[ $2 = BBB ]] then status=old fi sed -n "/$status/p" $1 >> output.txt #DDD old #ABC old ABC old DDD old ABC old |
|
|||
|
I have a different question on sed.
How do you delete everything after a particular string using sed? e.g. I have a file with three lines below: A100 ; B2000 ; B2000 C30 ; C30 ; C30 I want to delete everything after ";" to become like below: A100 B2000 C30 Any help will be greatly appreciated. |