The UNIX and Linux Forums  


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
Help needed in shell scripting himvat Shell Programming and Scripting 3 11-16-2008 02:49 PM
Help needed - ksh shell scripting subbu Shell Programming and Scripting 5 02-15-2008 12:53 PM
SHell Scripting Help Needed cskumar Shell Programming and Scripting 2 07-17-2006 02:55 AM
Help needed - shell scripting garric Shell Programming and Scripting 8 05-23-2006 07:08 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 4 Weeks Ago
computethis computethis is offline
Registered User
  
 

Join Date: Nov 2009
Posts: 9
sed/shell scripting - add line if needed and not allready there

I am writing a shell script that checks all .c files to see if they use fprintf or printf. If a file does, then the line #include <stdio.h> is added to the top of the file, unless it's already there.

This is what I've got:

Code:
#!/bin/sh
egrep -l f?printf *.c | while read file;
do sed -i '1i\
#include <stdio.h>' $file; 
done

The problem is that it doesn't check to see if <stio.h> is allready there, so I've been thinking about using

Code:
egrep -l f?printf *.c | grep -L '#include <stdio.h>

but this doesn't work because it anonimizes the files when I use the pipe.

Last edited by computethis; 4 Weeks Ago at 03:07 AM.. Reason: added code tags
 

Bookmarks

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 11:47 AM.


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