Replacing a particular position in a file thru shell script in Linux
My file content is
"4444412000 ":"444441001362":"Kodiak2Grp " "9880222221 ":"333331001362":"TestGrp1 " "3333312221 ":"333331333331":"TestGrp1 " "3333312221 ":"333333313331":"TestGrp1 " The file has three fields....Requirement is in the second column if the first 6 characters match the string then the first six characters only should be replaced with another string..[if the last 6 or the any combination of six characters in the second column matches other than first 6 characters, then it should not be replaced]...Any help on this?? say OLDSTR=333331 NEWSTR=777771 and the output should be "4444412000 ":"444441001362":"Kodiak2Grp " "9880222221 ":"777771001362":"TestGrp1 " "3333312221 ":"777771333331":"TestGrp1 " "3333312221 ":"333333313331":"TestGrp1 " the value of the OLDSTR and the NEWSTR will be changed programatically.. |
Code:
awk ' BEGIN { FS=":"} Code:
Code:
"4444412000 ":"444441001362":"Kodiak2Grp " |
what about bash script:
Code:
echo file | substituting by ${var,#old_prefix,new} actually, i'm "on-break" in work on a microtheft machine :( does anyone know a free online bash access? mustafa |
Can you install Cygwin on the MS box?
|
How about this ($1 is the string, $2 is the replacement, $3 is the file):
Code:
#!/bin/bash It should take any line "...":"...":"..." and turn it into "...": and "...":"...". Then "...":"..." is checked for "(before) which is replaced with "(after) then is put back together with "...":. (I'm sure I over-complicated it...) ta0kira |
hi,
i tried something else Code:
cat /dev/null > temp.2 # force empty file ,, mustafa |
Code:
#!/bin/bash ta0kira PS Quote:
|
What about perl ?
Code:
perl -pi -e 's/(.*:")(333331)(.*":.*)/${1}777771${3}/' file |
All times are GMT -5. The time now is 11:14 PM. |