Replacing a particular position in a file thru shell script in Linux
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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??
How about this ($1 is the string, $2 is the replacement, $3 is the file):
rm -f .$3
grep ".*" "$3" | while read nextline
begin="`echo "$nextline" | sed -r "s*\"[^\"\n]*\":\"[^\"\n]*\"$**"`"
end="`echo "$nextline" | sed -r "s*^$begin**"`"
end2="`echo "$end" | sed -r "s*^\"$1*/\"$2*"`"
echo "$begin$end2" >> .$3
echo "" > $3
grep ".*" ".$3" >> $3
rm -f .$3
Sorry, couldn't test it because I don't have a Linux box here right now.
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...)