The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
looking for files and modify if size matches viko Shell Programming and Scripting 3 02-18-2008 12:14 PM
how to permanently modify the open files 3rr0r_3rr0r UNIX for Dummies Questions & Answers 2 01-23-2007 12:40 AM
shell scripts that parse log files trueman82 Shell Programming and Scripting 4 11-22-2006 06:09 AM
Modify files amgo UNIX for Advanced & Expert Users 7 12-12-2005 09:19 AM
FTP Shell Scripts from Windows to Unix: files have exotic characters Laud12345 Shell Programming and Scripting 4 02-17-2005 05:57 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 01-17-2008
tpltp tpltp is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 30
Modify files through scripts

Hello, all

I want to implement some actions on the specified files, to modify some contents in the files, as follows:
File1:
****
name carol
birthday 830319
*******
name billy
birthday 831001
***************


____________________________
The asterisks mean there are a lot of other contents. I want to write a script to change the file as " Modify.ksh File1 000101" to modify all the birthdays to 000101? Are there any suggestions? For the easy way

NOTE: In the file, the birthday only appears in the two places.
  #2 (permalink)  
Old 01-17-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
You could embed this sed script in a shell script to do what you like


Code:
sed -i -e "s/birthday/& 000101/g" File1


Code:
#! /bin/ksh
# Assuming File1 and new BirthDate comes always
#
sed -i -e "s/birthday/& $2/g" $1

You need to have GNU sed to get the -i flag.
  #3 (permalink)  
Old 01-17-2008
tpltp tpltp is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 30
Thank you for your reply, VINO....

But if there is no installation of the GNU sed, are there any other options? Because this situation happened on me and I have no right to do an installation, so sad...
  #4 (permalink)  
Old 01-17-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,554
then you can pipe the output to a newfile and rename it back to original if desired
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 10:59 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