[SOLVED] Replacing multiple string in multiple files with awk
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
There is less than 2 hours left to vote in the 2015 LinuxQuestions.org Members Choice Awards. Click here to go to the polls. Vote now and make sure your voice is heard!
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.
echo -e "Please paste the string you have:\n[Note: Make sure you dont have comma/white space at the end]: "
n=`echo $string| grep -o ","|wc -l` #### Counts the number of fields you have in the string ###
n=$(( $n + 1 ))
echo "You have $n fields in the entered string"
while [ $m -le $n ]
y=`echo $string | cut -d"," -f$m | sed 's/ //'`
echo "Please enter the file name in which you'd like to insert $y:\n[Note: Make sure you have the file in the current working directory]"
sed -i "s:ref_t = x x:ref_t = $y $y:" "$fn" ### You can change the pattern here if you want ###
m=$(( $m + 1 ))
I wrote this depending on what i have understand from your post.. I'm posting it here,assuming it may help you in writing your own script.
Yes, the string is always comma and space separated.
The order of the files is depending on their name, they share same name, but are numbered starting from 0, like this:
file_0.txt, file_1.mdp, file_2.txt, etc.
The number of files is always same of the length of the string. With a small modificiation of RaviTezu's script (where it prompts for the file's name, that I want to modify), I think I can automatize it fairly easily.