![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Help needed please. | jerryboy78 | UNIX for Dummies Questions & Answers | 3 | 03-16-2008 02:06 PM |
| help needed | nnayagam | Shell Programming and Scripting | 2 | 03-07-2008 06:34 AM |
| Little help needed. | Netghost | AIX | 5 | 08-10-2006 02:29 PM |
| Help needed | dsravan | Shell Programming and Scripting | 2 | 07-20-2006 09:37 AM |
| awk help needed. | cskumar | Shell Programming and Scripting | 0 | 07-20-2006 07:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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-02-2005 at 03:42 AM.. |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|