![]() |
|
|
|
|
|||||||
| 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 |
| How to remove the specific lines from file using perl | dipakg | Shell Programming and Scripting | 4 | 06-10-2008 11:45 PM |
| Remove duplicates from File from specific location | gopikgunda | Shell Programming and Scripting | 1 | 04-08-2008 11:16 PM |
| remove specific lines from flat file using perl | meghana | Shell Programming and Scripting | 12 | 02-12-2008 05:50 PM |
| remove specific lines from a file | hcclnoodles | Shell Programming and Scripting | 14 | 09-07-2006 09:31 AM |
| How do you specific lines in a file? | hedgehog001 | UNIX for Dummies Questions & Answers | 2 | 08-22-2005 09:04 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
how to remove specific lines from a file
When restoring a file in my uninstall program I need to remove the lines I added to a file during the install. In between the file can be modified by the users.
Assume file1 is as follow: xxx str2 xxxx ..... ...The Following lines containing str* have to be removed... xxx str1 xxxx xxx str2 xxxxx xxxx aaa, xxx xxxxx str4 xxx Result: xxx str2 xxxx ..... xxxx aaa, xxx I know how to remove the line "The Following lines containing str* ...": ln=`grep -n 'The Following lines containing' | cut -d',' -f 1` sed $lnd file1 I also know how to remove the lines with str* in it with awk: awk 'BEGIN { FS=";" } { if ( $2 ~ /str*/ ) { print $0 } }' file1 > outputF However, how to do this without removing the lines with str* before the line "The Following lines containing str* have to be removed" ? (the first line in file1 for example). Any help would be greatly appreciated!! |
| Forum Sponsor | ||
|
|
|
|||
|
A cunning approach would be to generate a patch file at install time that would then remove the lines you added, that could be done by savinging a backup of the original and doing a diff at installation time, then deleting the backup. Then at uninstall time you apply the patch.
|
|
|||
|
Ygor:
That doesn't work on my sunOS 5.10. But thanks the same. summer_cherry: It works perfect! -and I've learned a lot about this nawk utility today. Thanks for your help! porter: That was what I did- however, I wanted the installation program to be able to run as many times as the users like without the need of uninstallation in between- and every time it runs it should be as clean as the first time... I thought that'd make it all a bit more dynamic... Thanks for the suggestion!! |
|
|||
|
Hey,
To delete a line where a pattern matches, you can use sed. sed '/^[Mm]ango/d' file1.txt Above command will delete all the lines which starts with the word Mango or mango. Similarly you can search the pattern in a line, if that will be found then delete the line. |