![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| compare XML/flat file with UNIX file system structure | shafi2all | High Level Programming | 6 | 08-15-2008 03:15 AM |
| Awk to convert a flat file to CSV file | rkumudha | Shell Programming and Scripting | 14 | 07-17-2008 10:48 PM |
| match string in a file to file in a directory | Jae | Shell Programming and Scripting | 5 | 01-19-2008 01:11 AM |
| Remove 5th character from Field1 & Print | Raynon | Shell Programming and Scripting | 9 | 12-14-2007 05:57 AM |
| Converting Pivot file to flat file | vskr72 | Shell Programming and Scripting | 2 | 10-18-2005 05:41 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Very weird. Checked, proof: cat fran4.awk Code:
BEGIN {
FScsv=","
FScfg=FS
if (sep=="") sep="."
qq=sprintf("%c", 034)
}
FNR==NR && FNR==1 {FS=FScsv;$1=$1}
FNR!=NR && FNR==1 {FS=FScfg; $1=$1}
FNR==NR {gsub(qq, "", $1);gsub(qq, "", $2); csv[$1]=$2; next}
!/{/ {
n=split($2, _a,sep)
for(i=1; i<=n; i++)
if (_a[i] in csv) _a[i]=csv[_a[i]]
for(i=1; i<=n; i++)
$2=(i==1) ? _a[i] : $2 sep _a[i]
}
1
cat test.csv Code:
"hello","byebye" "other","data" "hello2","byebye2" "hello3","byebye3" "other","data" cat services.txt Code:
define service{
use generic-service
service_description TCP_80
host_name hello,hello2,hello3,nochangematch
contact_groups
check_command
}
Running code: nawk -v sep=',' -f fran4.awk test.csv services.txt Code:
define service{
use generic-service
service_description TCP_80
host_name hello,byebye2,byebye3,nochangematch
contact_groups
check_command
}
Didn't change first hello cat nagios.cfg.txt Code:
define host{
use generic-host
host_name hello
alias hello.hello
address 127.0.0.1
contact_groups mymail
parents hello3
}
Running code: nawk -v sep='.' -f fran4.awk test.csv nagios.cfg.txt Code:
define host{
use generic-host
host_name hello
alias hello.hello
address 127.0.0.1
contact_groups mymail
parents byebye3
}
Changed only parents field. Is fran4.awk latest code, matches yours? Just in case did for all files dos2unix as well and: file -i fran4.awk test.csv nagios.cfg.txt services.txt Code:
fran4.awk: text/plain charset=us-ascii test.csv: text/plain charset=us-ascii nagios.cfg.txt: text/plain charset=us-ascii services.txt: text/plain charset=us-ascii |
|
||||
|
cat -vet nagios.cfg.txt Code:
define host{$
use generic-host$
host_name hello$
alias hello.hello$
address 127.0.0.1$
contact_groups mymail$
parents hello3$
}$
cat -vet test.csv Code:
"hello","byebye"$ "other","data"$ "hello2","byebye2"$ "hello3","byebye3"$ "other","data"$ cat -vet services.txt Code:
define service{$
use generic-service$
service_description TCP_80$
host_name hello,hello2,hello3,nochangematch$
contact_groups $
check_command $
}$
cat -vet fran4.awk Code:
BEGIN {$
FScsv=","$
FScfg=FS$
$
if (sep=="") sep="."$
$
qq=sprintf("%c", 034)$
}$
FNR==NR && FNR==1 {FS=FScsv;$1=$1}$
FNR!=NR && FNR==1 {FS=FScfg; $1=$1}$
FNR==NR {gsub(qq, "", $1);gsub(qq, "", $2); csv[$1]=$2; next}$
$
!/{/ {$
n=split($2, _a,sep)$
for(i=1; i<=n; i++)$
if (_a[i] in csv) _a[i]=csv[_a[i]]$
for(i=1; i<=n; i++)$
$2=(i==1) ? _a[i] : $2 sep _a[i]$
}$
1$
|
|
||||
|
Yep, if changing to "other" then works cat nagios.cfg.txt Code:
define host{
use generic-host
host_name other
alias other.other
address 127.0.0.1
contact_groups mymail
parents hello3
}
nawk -v sep='.' -f fran4.awk test.csv nagios.cfg.txt Code:
define host{
use generic-host
host_name data
alias data.data
address 127.0.0.1
contact_groups mymail
parents byebye3
}
Works, like a champ Then again with this concept: cat nagios.cfg.txt Code:
define host{
use generic-host
host_name hello
alias other.hello2
address 127.0.0.1
contact_groups mymail
parents hello3
}
nawk -v sep='.' -f fran4.awk test.csv nagios.cfg.txt Code:
define host{
use generic-host
host_name hello
alias data.byebye2
address 127.0.0.1
contact_groups mymail
parents byebye3
}
You see, hello in host_name field didn't change. all other fields okey. This is like my awk hates "hello". It want's it to be "hell' ![]() Just joking.. but seriously.. Very weird case. |
|
||||
|
Quote:
Code:
define host{
use generic-host
host_name hello
alias other.hello2
address 127.0.0.1
contact_groups mymail
parents hello3
}
cat test2.csv Code:
"other","data" "hello","byebye" "hello2","byebye2" "hello3","byebye3" "other","data" nawk -v sep='.' -f fran4.awk test2.csv nagios.cfg.txt Code:
define host{
use generic-host
host_name byebye
alias data.byebye2
address 127.0.0.1
contact_groups mymail
parents byebye3
}
So now it changed. Hmm whats the case with your given test.csv then? diff test.csv test2.csv Code:
1d0 < "hello","byebye" 2a2 > "hello","byebye" |
![]() |
| Bookmarks |
| Tags |
| host_name, nagios, update |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|