The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
Script required to get a required info from file. Pls. help me. ntgobinath Shell Programming and Scripting 2 05-31-2008 08:34 AM
Getting Following problem when opening shell script (Very Urgent) sunitachoudhury Shell Programming and Scripting 1 03-31-2008 07:01 AM
Urgent: selecting unique specific content of a file using shell script jisha Shell Programming and Scripting 2 01-08-2008 08:45 AM
Deleting lines inside a file without opening the file toms Shell Programming and Scripting 3 09-24-2007 07:58 AM
Very Urgent help required in Shell Program Suppandi Shell Programming and Scripting 1 12-09-2005 08:33 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 07-20-2006
naan naan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 31
Urgent help required in deleting a line without opening a file usinga shell script

Hi,

I need a help in deleting a line matching a particular pattern in a file using shell script without opening the file. The file is a .c/.cpp file. Is it possible?

Thanks
  #2 (permalink)  
Old 07-20-2006
girish.karulkar girish.karulkar is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
Quote:
Originally Posted by naan
Hi,

I need a help in deleting a line matching a particular pattern in a file using shell script without opening the file. The file is a .c/.cpp file. Is it possible?

Thanks
Hi naan, you can overright the file.
eg. I have a file name.cpp & i wanna delete line with a text "test file". then do it like this

cat name.cpp | grep -v "test file" > name.cpp

"grep -v "test file" will display the name.cpp without line containing words "test file" & " >name.cpp" will overright the previous file

Regds,
Girish
  #3 (permalink)  
Old 07-20-2006
girish.karulkar girish.karulkar is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
Smile delete line with Overrighting the file

Hi naan, you can delet th eline by overrighting the file.
eg. I have a file name.cpp & i wanna delete line containing words "test file". then do it like this

cat name.cpp | grep -v "test file" > name.cpp

"grep -v "test file" will display the name.cpp without line co ntaining words "test file" & " >name.cpp" will overright the previous file

Regds,
Girish
  #4 (permalink)  
Old 07-20-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by girish.karulkar
cat name.cpp | grep -v "test file" > name.cpp
That command will wipe out the complete file.

You should be doing
Code:
grep -v "test file" name.cpp > name.cpp.new
mv name.cpp.new name.cpp
  #5 (permalink)  
Old 07-20-2006
girish.karulkar girish.karulkar is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 4
Quote:
Originally Posted by vino
That command will wipe out the complete file.

You should be doing
Code:
grep -v "test file" name.cpp > name.cpp.new
mv name.cpp.new name.cpp
Yes. I do agree !
  #6 (permalink)  
Old 07-20-2006
naan naan is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 31
Additional help

Thanks a lot for the input...So can we use the same solution while writing a batch DOS program to delete a particular line from a set of files within a folder so that it recursively goes and delete the line in all the files.
  #7 (permalink)  
Old 07-20-2006
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
I think by Dos batch program you mean a shell script, if that is the case then try this:
Code:
#! /bin/ksh

for i in *.cpp;
do
grep -v "test file" $i > $i.new
mv $i.new $i
done
Regards,
Tayyab
Sponsored Links
Closed Thread

Bookmarks

Tags
sed delete line

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0