![]() |
|
|
|
|
|||||||
| 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 | nnayagam | Shell Programming and Scripting | 2 | 03-07-2008 03: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 |
| Sed help needed | stevefox | Shell Programming and Scripting | 5 | 12-04-2005 10:44 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Could someone please tell me the command to delete a line with a specific word and also deleting all lines below this line? I want this to be done without opening the file itself using SED in HP Unix?
e.g. I have a text file input.txt and with 4 lines of text below: John 123 A--G Chris 190 C--T Mat 098 F--K Mike 674 B--N Pat 838 L--U I want to delete the line which has string "098" and all lines below this line to look like the below: John 123 A--G Chris 190 C--T |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I think below code can cater to ur need.
csplit filename "/`grep 098 filename`/" will create files with xx prefix xx00 file will contain what u need. |
|
#3
|
|||
|
|||
|
This will help u ...
sed '/098/,$ d' filename this deletes all lines starting from the first line having 098 uptill the end of file ... |
|
#4
|
|||
|
|||
|
Thanks everyone!
It worked! |
|
#5
|
|||
|
|||
|
Could someone please tell me how to make a Korn Shell to do the below:
I have the files below with the same format (different data) as mentioned previously and I want a shell to run "sed '/098/,$ d' filename" on all of the files in the directory. list20051001.txt list20051002.txt list20051003.txt ... list20051031.txt |
|
#6
|
|||
|
|||
|
Hi
Try the following: for filename in `ls directory ` do sed '/098/,$ d' $filename > $filename.1 mv $filename.1 $filename done |
|
#7
|
|||
|
|||
|
Niyati
Thanks for your replay. However I get the error below and it isn't working: ./testshell.ksh[4]: ls /MyFolder/Test.1: cannot create mv: ls: cannot access: No such file or directory mv: /MyFolder/Test.1: cannot access: No such file or directory mv: ls: cannot access: No such file or directory Below is the contents of testshell.ksh: #!/bin/ksh for filename in 'ls /MyFolder/Test' do sed '/098/,$ d' $filename > $filename.1 mv $filename.1 $filename done Below is the contents of /MyFolder/Test directory: list1.txt list12.txt list2.txt list3.txt Any help will be appreciated. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|