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
Config::Model::models::LCDd(3pm)			User Contributed Perl Documentation			  Config::Model::models::LCDd(3pm)

NAME
Config::Model::models::LCDd - Configuration class LCDd VERSION
version 2.021 DESCRIPTION
Configuration classes used by Config::Model LCDd.conf -- configuration file for the LCDproc server daemon LCDd This file contains the configuration for the LCDd server. The format is ini-file-like. It is divided into sections that start at markers that look like [section]. Comments are all line-based comments, and are lines that start with ' The server has a 'central' section named [server]. For the menu there is a section called [menu]. Further each driver has a section which defines how the driver acts. The drivers are activated by specifying them in a driver= line in the server section, like: Driver=curses This tells LCDd to use the curses driver. The first driver that is loaded and is capable of output defines the size of the display. The default driver to use is curses. If the driver is specified using the -d <driver> command line option, the Driver= options in the config file are ignored. The drivers read their own options from the respective sections. Model information extracted from template /etc/LCDd.conf BUGS
This model does not support to load several drivers. Loading several drivers is probably a marginal case. Please complain to the author if this assumption is false Elements server Optional. Type node. menu Optional. Type node. bayrad Optional. Type warped_node. CFontz Optional. Type warped_node. CFontzPacket Optional. Type warped_node. curses Optional. Type warped_node. CwLnx Optional. Type warped_node. ea65 Optional. Type warped_node. EyeboxOne Optional. Type warped_node. g15 Optional. Type warped_node. glcd Optional. Type warped_node. glcdlib Optional. Type warped_node. glk Optional. Type warped_node. hd44780 Optional. Type warped_node. icp_a106 Optional. Type warped_node. IOWarrior Optional. Type warped_node. imon Optional. Type warped_node. imonlcd Optional. Type warped_node. IrMan Optional. Type warped_node. irtrans Optional. Type warped_node. joy Optional. Type warped_node. lb216 Optional. Type warped_node. lcdm001 Optional. Type warped_node. lcterm Optional. Type warped_node. lirc Optional. Type warped_node. lis Optional. Type warped_node. MD8800 Optional. Type warped_node. mdm166a Optional. Type warped_node. ms6931 Optional. Type warped_node. mtc_s16209x Optional. Type warped_node. MtxOrb Optional. Type warped_node. mx5000 Optional. Type warped_node. NoritakeVFD Optional. Type warped_node. picolcd Optional. Type warped_node. pyramid Optional. Type warped_node. sed1330 Optional. Type warped_node. sed1520 Optional. Type warped_node. serialPOS Optional. Type warped_node. serialVFD Optional. Type warped_node. shuttleVFD Optional. Type warped_node. stv5730 Optional. Type warped_node. SureElec Optional. Type warped_node. svga Optional. Type warped_node. text Optional. Type warped_node. t6963 Optional. Type warped_node. tyan Optional. Type warped_node. ula200 Optional. Type warped_node. sli Optional. Type warped_node. vlsys_m428 Optional. Type warped_node. xosd Optional. Type warped_node. SEE ALSO
o cme o Config::Model::models::LCDd::CFontz o Config::Model::models::LCDd::CFontzPacket o Config::Model::models::LCDd::CwLnx o Config::Model::models::LCDd::EyeboxOne o Config::Model::models::LCDd::IOWarrior o Config::Model::models::LCDd::IrMan o Config::Model::models::LCDd::MD8800 o Config::Model::models::LCDd::MtxOrb o Config::Model::models::LCDd::NoritakeVFD o Config::Model::models::LCDd::SureElec o Config::Model::models::LCDd::bayrad o Config::Model::models::LCDd::curses o Config::Model::models::LCDd::ea65 o Config::Model::models::LCDd::g15 o Config::Model::models::LCDd::glcd o Config::Model::models::LCDd::glcdlib o Config::Model::models::LCDd::glk o Config::Model::models::LCDd::hd44780 o Config::Model::models::LCDd::icp_a106 o Config::Model::models::LCDd::imon o Config::Model::models::LCDd::imonlcd o Config::Model::models::LCDd::irtrans o Config::Model::models::LCDd::joy o Config::Model::models::LCDd::lb216 o Config::Model::models::LCDd::lcdm001 o Config::Model::models::LCDd::lcterm o Config::Model::models::LCDd::lirc o Config::Model::models::LCDd::lis o Config::Model::models::LCDd::mdm166a o Config::Model::models::LCDd::menu o Config::Model::models::LCDd::ms6931 o Config::Model::models::LCDd::mtc_s16209x o Config::Model::models::LCDd::mx5000 o Config::Model::models::LCDd::picolcd o Config::Model::models::LCDd::pyramid o Config::Model::models::LCDd::sed1330 o Config::Model::models::LCDd::sed1520 o Config::Model::models::LCDd::serialPOS o Config::Model::models::LCDd::serialVFD o Config::Model::models::LCDd::server o Config::Model::models::LCDd::shuttleVFD o Config::Model::models::LCDd::sli o Config::Model::models::LCDd::stv5730 o Config::Model::models::LCDd::svga o Config::Model::models::LCDd::t6963 o Config::Model::models::LCDd::text o Config::Model::models::LCDd::tyan o Config::Model::models::LCDd::ula200 o Config::Model::models::LCDd::vlsys_m428 o Config::Model::models::LCDd::xosd COPYRIGHT
2011, Dominique Dumont 1999-2011, William Ferrell and others LICENSE
GPL-2 perl v5.14.2 2012-11-09 Config::Model::models::LCDd(3pm)
All times are GMT -4. The time now is 06:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy