![]() |
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 |
| How to remove the specific lines from file using perl | dipakg | Shell Programming and Scripting | 4 | 06-11-2008 02:45 AM |
| Remove duplicates from File from specific location | gopikgunda | Shell Programming and Scripting | 1 | 04-09-2008 02:16 AM |
| remove specific lines from flat file using perl | meghana | Shell Programming and Scripting | 12 | 02-12-2008 09:50 PM |
| remove specific lines from a file | hcclnoodles | Shell Programming and Scripting | 14 | 09-07-2006 12:31 PM |
| How do you specific lines in a file? | hedgehog001 | UNIX for Dummies Questions & Answers | 2 | 08-23-2005 12:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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!! |
|
||||
|
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. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|