![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| Need help regarding replacing a part of string | veerapureddy | Shell Programming and Scripting | 1 | 03-17-2008 09:02 AM |
| how to get the last part of a string followed by a pattern | bluemoon1 | Shell Programming and Scripting | 4 | 09-08-2007 12:10 PM |
| Extracting part of a string | sam_78_nyc | Shell Programming and Scripting | 8 | 04-25-2007 08:37 PM |
| ksh: A part of variable A's name is inside of variable B, how to update A? | pa3be | Shell Programming and Scripting | 4 | 03-30-2005 12:29 PM |
| using sed to replace a part of string | csejl | Shell Programming and Scripting | 6 | 01-12-2004 11:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Repacing part of string with a variable
I have following strings in a file
DUPTASMTRMMBAL,20070416200704160117232101172321,,,,,,,@@@Y DUPTASMTRMMCON,20070416200704160127189901271899,,,,,,,@@@Y DUPTASMTRMMHG,,20070416200704160112051001120510,,,,,,,@@@Y What i need to do is replace the date 20070416 with anoth date which is stored in variable enddate (enddate is result of certain calculations). What i am tryning is this :- for D in `cat file`;do str1=`echo $D|cut -c1-15` date1=`echo $D|cut -c16-23` date2=`echo $D|cut -c24-31` str2=`echo $D|cut -c32-` enddate=$enddate D=$str1$enddate$enddate$str2 done This is not working. Can someone please tell me an alternate method, using sed or awk. And also tell me why is this not working. ![]() |
|
||||
|
Code:
sed "s/20070416/$enddate/g" file > temp mv temp file Code:
for D in `cat file`;do str1=`echo $D|cut -c1-15` date1=`echo $D|cut -c16-23` date2=`echo $D|cut -c24-31` str2=`echo $D|cut -c32-` enddate=$enddate echo $str1$enddate$enddate$str2 >> temp done mv temp file |
|
||||
|
[QUOTE=anbu23;302127633]
Code:
sed "s/20070416/$enddate/g" file > temp mv temp file And sed "s/$date1/$enddate/g" file > temp does not work ![]() |
|
||||
|
Code:
for D in `cat file`;do str1=`echo $D|cut -c1-15` date1=`echo $D|cut -c16-23` date2=`echo $D|cut -c24-31` str2=`echo $D|cut -c32-` enddate=$enddate echo $str1$enddate$enddate$str2 >> temp done mv temp file I have already tried this option. For some reason, I am getting repeated data. What i mean is, if there are three rows in file then there are 39 rows in temp. The three rows are repeated 13 times. I am not able to understand why is this happening. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|