![]() |
|
|
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 |
| can someone help me with modifying this file | eamani_sun | Shell Programming and Scripting | 2 | 05-22-2008 02:15 PM |
| Modifying a csv file from Shell Script | not4google | Shell Programming and Scripting | 2 | 11-21-2006 06:47 AM |
| Modifying the final output file | charbel | Shell Programming and Scripting | 5 | 10-10-2006 02:36 PM |
| Modifying the URL to point to another location in a .sh UNIX file | pjanakir | UNIX for Dummies Questions & Answers | 6 | 01-25-2006 03:19 PM |
| Modifying binary file by editing Hex values ? | Nicol | UNIX for Advanced & Expert Users | 4 | 11-04-2005 08:25 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Help need in modifying the text of .txt file
Hi All,
I've written a shell script in which i defined two varibles for example: str=1.0.0.15 timeStamp=2008.03.08 now using this varibles i need to modify a text file. The text content looks like this ************************ * packageNumber : 1.0.0.14 * * date : 2008.02.08 * ************************ after executing the shell script, the text must look like this ************************ * packageNumber : 1.0.0.15 * * date : 2008.03.08 * ************************ Could anybody help me in resolving this issue? Thanks, Vinna |
|
||||
|
I'm sure someone will have a better way of achieving this but here's one version: ~/scripts/play % cat file1 ************************ * packageNumber : 1.0.0.14 * * date : 2008.02.08 * ************************ ~/scripts/play % cat aa Code:
#!/bin/sh
str=1.0.0.15
timeStamp=2008.03.08
file=${HOME}/scripts/play/file1
rep1=`grep packageNumber ${file} | awk '{print $4}'`
rep2=`grep date ${file} | awk '{print $4}'`
sed -e 's/'"${rep1}"'/'"${str}"'/' -e 's/'"${rep2}"'/'"${timeStamp}"'/' $file > ${file}.tmp
mv ${file}.tmp $file
~/scripts/play % aa ~/scripts/play % cat file1 ************************ * packageNumber : 1.0.0.15 * * date : 2008.03.08 * ************************ ~/scripts/play % |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|