[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.
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.