Sponsored Content
Top Forums Shell Programming and Scripting Using multiple gsub() function under a loop in awk Post 302894585 by useless79 on Wednesday 26th of March 2014 09:11:02 AM
Old 03-26-2014
thanks it is working.

just wanted to know what is the use of semicolon ; for multiple gsub() used under same loop. is it mandatory to use ; after each gsub() under a given loop ?

for (i in array)
{
gsub("^"i, array[i]) ;
gsub("Configuration file for "i, "Configuration file for " array[i])
}



moreover my awk cmd is in one line and looks complex , how can i break this to multiple line ? I am using this awk command under a shell script .





Code:
#!/usr/bin/sh

fix_config()
{
  if [ -r /etc/Config ] ; then
    awk '{FS=":"} FNR==NR {array[$1]=$2; next} {FS=" "} FNR!=NR {for (i in array) {gsub("^"i, array[i]) gsub("Test "i, "Test "array[i]) ; {if(toupper($0) ~ toupper(i)) {gsub("! Configuration for "toupper(i), "! Configuration for " toupper(array[i]))}}}} !/This is my conf/  1'  /etc/Mapping  /etc/Config  > Config.bk
  fi
}


fix_config



Thanks.........






thanks...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Handling multiple fields of a database file for toupper() function in awk

hello everyone.... script is: To convert the contents of a database file into uppercase my code is: printf "%s\n" , $2 | awk '{print toupper($2)}' emp.lst i m able to do only for one field.....didn't get any sources for handling multiple fields. please suggest me for multiple... (1 Reply)
Discussion started by: Priyanka Bhati
1 Replies

2. Shell Programming and Scripting

Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory I meet a problem during the for loop in my script. Some file names contain spaces. ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};' -rw-r--r-- 1 was61 ... (2 Replies)
Discussion started by: Scofield38
2 Replies

3. Shell Programming and Scripting

Loop through multiple rows using awk

Hi, i'm been browsing through the threads on how to do looping of multiple lines in awk but havent found the one i needed. I have a data which looks like this below. I need to compute for the monthly average of values per record and i used the awk argument below. how do i tell awk to execute the... (9 Replies)
Discussion started by: ida1215
9 Replies

4. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

5. UNIX for Dummies Questions & Answers

awk: multiple gsub in a script

%%%%% (1 Reply)
Discussion started by: lucasvs
1 Replies

6. Shell Programming and Scripting

awk gsub multiple fields

Hi, I am trying to execute this line awk -F ";" -v OFS=";" '{gsub(/\./,",",$6); print}' FILE but for multiple fields $6 $7 $8 Do you have a suggstion? Tried: awk -F ";" -v OFS="";"" "function GSUB( F ) {gsub(/\./,\",\",$F); print} { GSUB( 6 ); GSUB( 7 ); GSUB( 8 ) } 1"... (2 Replies)
Discussion started by: nakaedu
2 Replies

7. Shell Programming and Scripting

Gsub function in awk

Hello, I had some difficulty to understand the gsub function and maybe the regex in this script to remove all the punctuations: awk 'gsub(//, " ", $0)' text.txtFile text.txt: This is a test for gsub I typed this random text file which contains punctuation like ,.;!'"?/\ etc. The script... (6 Replies)
Discussion started by: yifangt
6 Replies

8. UNIX for Beginners Questions & Answers

awk GSUB read field values from multiple text files

My program run without error. The problem I am having. The program isn't outputting field values with the column headers to file.txt. Each of the column headers in file.txt has no data. MEMSIZE SECOND SASFoundation Filename The output results in file.txt should show: ... (1 Reply)
Discussion started by: dellanicholson
1 Replies

9. Shell Programming and Scripting

awk gsub command to replace multiple spaces

Hi Forum. I'm trying to cleanup the following data elements (To remove any occurences of commas and any extra spaces) while preserving the <TAB> delimiter using awk gsub but I have not been successful. Original Data: 4365 monte des source rue,, ,<TAB>trevost<TAB>QC Desired Data:... (1 Reply)
Discussion started by: pchang
1 Replies

10. Shell Programming and Scripting

Make awk gsub take value of for loop

I am running Debian, mksh shell and #!/bin/mksh script. Here is one instance I am trying to match. There are other level and n values, but they must be gathered in numerical order or the program will not work properly: level="0" n="0" Here is my code which does not work: { for (a = 0; a <=... (15 Replies)
Discussion started by: bedtime
15 Replies
Gnome2::Config(3pm)					User Contributed Perl Documentation				       Gnome2::Config(3pm)

NAME
Gnome2::Config METHODS
boolean = Gnome2::Config->get_bool ($path) o $path (string) boolean = Gnome2::Config::Private->get_bool ($path) o $path (string) Gnome2::Config->set_bool ($path, $value) o $path (string) o $value (boolean) Gnome2::Config::Private->set_bool ($path, $value) o $path (string) o $value (boolean) list = Gnome2::Config->get_bool_with_default ($path) o $path (string) Returns a boolean indicating whether the default was used and the actual value. list = Gnome2::Config::Private->get_bool_with_default ($path) o $path (string) Gnome2::Config->clean_file ($path) o $path (string) Gnome2::Config::Private->clean_file ($path) o $path (string) Gnome2::Config->clean_key ($path) o $path (string) Gnome2::Config::Private->clean_key ($path) o $path (string) Gnome2::Config->clean_section ($path) o $path (string) Gnome2::Config::Private->clean_section ($path) o $path (string) Gnome2::Config->drop_all Gnome2::Config->drop_file ($path) o $path (string) Gnome2::Config::Private->drop_file ($path) o $path (string) double = Gnome2::Config->get_float ($path) o $path (string) double = Gnome2::Config::Private->get_float ($path) o $path (string) Gnome2::Config->set_float ($path, $value) o $path (string) o $value (double) Gnome2::Config::Private->set_float ($path, $value) o $path (string) o $value (double) list = Gnome2::Config->get_float_with_default ($path) o $path (string) Returns a boolean indicating whether the default was used and the actual value. list = Gnome2::Config::Private->get_float_with_default ($path) o $path (string) boolean = Gnome2::Config->has_section ($path) o $path (string) boolean = Gnome2::Config::Private->has_section ($path) o $path (string) scalar = Gnome2::Config->init_iterator ($path) o $path (string) scalar = Gnome2::Config::Private->init_iterator ($path) o $path (string) scalar = Gnome2::Config->init_iterator_sections ($path) o $path (string) scalar = Gnome2::Config::Private->init_iterator_sections ($path) o $path (string) integer = Gnome2::Config->get_int ($path) o $path (string) integer = Gnome2::Config::Private->get_int ($path) o $path (string) Gnome2::Config->set_int ($path, $value) o $path (string) o $value (integer) Gnome2::Config::Private->set_int ($path, $value) o $path (string) o $value (integer) list = Gnome2::Config->get_int_with_default ($path) o $path (string) Returns a boolean indicating whether the default was used and the actual value. list = Gnome2::Config::Private->get_int_with_default ($path) o $path (string) Gnome2::Config->pop_prefix Gnome2::Config->push_prefix ($path) o $path (string) string = Gnome2::Config->get_real_path ($path) o $path (string) string = Gnome2::Config::Private->get_real_path ($path) o $path (string) string = Gnome2::Config->get_string ($path) o $path (string) string = Gnome2::Config::Private->get_string ($path) o $path (string) Gnome2::Config->set_string ($path, $value) o $path (string) o $value (string) Gnome2::Config::Private->set_string ($path, $value) o $path (string) o $value (string) list = Gnome2::Config->get_string_with_default ($path) o $path (string) Returns a boolean indicating whether the default was used and the actual value. list = Gnome2::Config::Private->get_string_with_default ($path) o $path (string) boolean = Gnome2::Config->sync boolean = Gnome2::Config->sync_file ($path) o $path (string) boolean = Gnome2::Config::Private->sync_file ($path) o $path (string) string = Gnome2::Config->get_translated_string ($path) o $path (string) string = Gnome2::Config::Private->get_translated_string ($path) o $path (string) Gnome2::Config->set_translated_string ($path, $value) o $path (string) o $value (string) Gnome2::Config::Private->set_translated_string ($path, $value) o $path (string) o $value (string) list = Gnome2::Config->get_translated_string_with_default ($path) o $path (string) list = Gnome2::Config::Private->get_translated_string_with_default ($path) o $path (string) scalar = Gnome2::Config->get_vector ($path) o $path (string) scalar = Gnome2::Config::Private->get_vector ($path) o $path (string) Gnome2::Config->set_vector ($path, $value) o $path (string) o $value (scalar) Gnome2::Config::Private->set_vector ($path, $value) o $path (string) o $value (scalar) list = Gnome2::Config->get_vector_with_default ($path) o $path (string) Returns a boolean indicating whether the default was used and the actual value. list = Gnome2::Config::Private->get_vector_with_default ($path) o $path (string) SEE ALSO
Gnome2 COPYRIGHT
Copyright (C) 2003-2004 by the gtk2-perl team. This software is licensed under the LGPL. See Gnome2 for a full notice. perl v5.14.2 2011-11-16 Gnome2::Config(3pm)
All times are GMT -4. The time now is 02:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy