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
question to build a shell script vishalpatel03 Shell Programming and Scripting 5 12-12-2007 12:45 PM
Build script for all shells vino Shell Programming and Scripting 9 04-14-2005 01:25 AM
Script Build mewalter Shell Programming and Scripting 3 07-09-2002 06:30 PM
I want to build a script mewalter Shell Programming and Scripting 2 07-01-2002 07:32 PM
Build my box... KyPeN UNIX for Dummies Questions & Answers 7 03-02-2002 10:31 PM

Closed Thread
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
  #1 (permalink)  
Old 07-08-2002
mewalter mewalter is offline
Registered User
  
 

Join Date: Jun 2002
Location: Gaborone, Botswana
Posts: 8
I want to build a script

I have this script

sed -e '$q' -e 's/I/D/g' <inputfile> outfile

which replaces I by D...

I have to run this script in 90 files which their filename starts with CD*. I want to call all these files and execute this command once.
Or schedule it to be executed at 1600hrs every day.

I want to output to the same i.e I'm modifying these file so input file has to have the same file as the output.

thanx forwarded
  #2 (permalink)  
Old 07-08-2002
Kevin Pryke Kevin Pryke is offline
Registered User
  
 

Join Date: Feb 2002
Location: Bradford, UK
Posts: 70
you can do this

#!bin/sh
for file in `ls CD*`
do
sed -e 's/I/D/g' < $file > $file.out
mv $file.out $file
done


If you want to run it at a specific time, use the cron command there have been plenty of posts on this site about it already.
  #3 (permalink)  
Old 07-08-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Just curious what your $q is doing? From the syntax it looks like another sed command....just something I learnt the other day...

Quote:
Inside single quotes, what you see is what you get. No character has any special meaning inside single quotes. So variables won't expand. Use double quotes
  #4 (permalink)  
Old 07-08-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,122
He actually doesn't want to change the last line. 'q' is a command that makes sed quit. '$' addresses the last line. So when the last line is encountered, sed exits so that second command never runs. See this thread.
  #5 (permalink)  
Old 07-08-2002
peter.herlihy peter.herlihy is offline
Registered User
  
 

Join Date: Nov 2001
Location: New Zealand
Posts: 333
Ah, very clever....context does help.
  #6 (permalink)  
Old 07-15-2002
mewalter mewalter is offline
Registered User
  
 

Join Date: Jun 2002
Location: Gaborone, Botswana
Posts: 8
Thumbs up Its working

txs a lot...its working..

I want build a script which will alert me by outlook mail about backup status
  #7 (permalink)  
Old 07-31-2002
kjd kjd is offline
Registered User
  
 

Join Date: Jul 2002
Location: TX, USA
Posts: 6
perl -pi -e

The -i option in Perl will edit the specified file "in place", so you don't have to mess with moving files around.

% echo "eat food" >> test.txt
% echo "eat more food" >> test2.txt
% perl -pi -e 's/food/pie/g' *
% cat test.txt
eat pie
% cat test2.txt
eat more pie

-i takes an optional argument. If specified, a backup will be saved with the argument as the file's extension.

% perl -pi'.bak' -e 's/pie/chicken/g' *
% ls
test.txt test.txt.bak test2.txt test2.txt.bak
% cat test.txt
eat chicken
% cat test.txt.bak
eat pie
Closed Thread

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 03:45 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