Help with awk and conf file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk and conf file
# 1  
Old 05-29-2011
Help with awk and conf file

hello

i have a configuration file with some fields, for example:

Code:
#file conf.cfg
name;object;var1;var2;var8


then i have a csv data file:
Code:
var1;var2;var3;var4;var5;var6;var7;var8;var9
aaa;bbb;ccc;ddd;eee;fff;ggg;hhh;iii
...


now i should read the conf.cfg file and extract the columns on the csv data file corresponding to the variables on the conf.cfg

So i have to obtain:

Code:
var1;var2;var8
aaa;bbb;hhh
...


please help
thanks!
# 2  
Old 05-29-2011
Code:
awk -F\; 'NR==FNR{for (i=3;i<=NF;i++) a[$i];next}
            FNR==1{for (i=1;i<=NF;i++) if ($i in a)  b[++j]=i }
            {for (i=1;i<=j;i++) printf $(b[i]) FS;printf RS}' conf.cfg input.csv

# 3  
Old 05-30-2011
Quote:
Originally Posted by rdcwayx
Code:
awk -F\; 'NR==FNR{for (i=3;i<=NF;i++) a[$i];next}
            FNR==1{for (i=1;i<=NF;i++) if ($i in a)  b[++j]=i }
            {for (i=1;i<=j;i++) printf $(b[i]) FS;printf RS}' conf.cfg input.csv



ok thanks now i have only a problem

my input.csv has got a different separator from conf.cfg:

conf.cfg has ;
input.csv has ~

how i can insert the second operator?
# 4  
Old 05-30-2011
Code:
awk -F\; 'NR==FNR{for (i=3;i<=NF;i++) a[$i];next}
            FNR==1{for (i=1;i<=NF;i++) if ($i in a)  b[++j]=i }
            {for (i=1;i<=j;i++) printf $(b[i]) FS;printf RS}' conf.cfg FS="~" input.csv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Configure resolv.conf and nsswitch.conf

Hi, I've installed Solaris 11.3(live media) and configured DNS. Everytime I reboot the server, resolv.conf got deleted and it created a new nsswitch.conf. I used below to configure both settings: # svccfg -s dns/client svc:/network/dns/client> setprop config/nameserver = (xx.xx.xx.aa... (1 Reply)
Discussion started by: flexihopper18
1 Replies

2. Shell Programming and Scripting

Script to update rsyslog.conf and auditd.conf

Hello all, Newbie here. I'm currently tasked with updating rsyslog.conf and auditd.conf on a large set of servers. I know the exact logging configurations that I want to enable. I have updated both files on on a server and hope to use the updated files as a template for the rest of the... (3 Replies)
Discussion started by: Mide
3 Replies

3. Red Hat

Restore grub.conf file

Hi guys, I will truly appreciate your help with this issue. If you do not have a backup copy of your grub.conf file, and for some reason the file got damaged or missing, how will you go about restoring it? Thanks for your kind assistance. (3 Replies)
Discussion started by: cjashu
3 Replies

4. Shell Programming and Scripting

Conf file entry.

Hi, Lets say I have a script which reads a conf file (say MASTERFILE) line by line to fetch file_name, source_path, dest_path. But currently, here the file name are static for eg: ABC.txt or XYZ.txt. So i have hard-coded in the conf file. So what happens that the script picks up the file_name... (1 Reply)
Discussion started by: amit.mathur08
1 Replies

5. UNIX for Advanced & Expert Users

Help me at squid.conf file

Hi all, i have a scenario below: <========> <=========> Internet With IP: -Local: 10.0.0.2 -Squid: 2NICs (10.0.0.1 and 192.168.100.1) -Internet: 192.168.100.2 * On Squid: hosting a website name www.sample.com * On Local: hosting a website name www.abc.sample.com * Complete DNS... (0 Replies)
Discussion started by: kidzer0
0 Replies

6. UNIX for Advanced & Expert Users

How can i tell which conf file it is using

i have this program running on my solaris and there are two identical config files, i am not sure which one is being used by this program but I am sure it uses one of them. I run lsof -p {pid} but it does not show which config file has been read by this program, what i am doing wrong? thanks (4 Replies)
Discussion started by: fedora
4 Replies

7. Solaris

basic question on sd.conf and lpc.conf file

Hello Guys, Do we need to configure this file only if we add SAN disk or even if we add local disk, do we need to modify? (4 Replies)
Discussion started by: mokkan
4 Replies

8. UNIX for Advanced & Expert Users

Configuring snmpd.conf and snmptrapd.conf

HI, I want a help for Configuring snmpd.conf and snmptrapd.conf (i.e Configuring SNMP) for receiving TRAPS in my networks. I am using RHEL4.0 OS. Please tell me How I can configure above two files in a proper way and at an advanced level. Especially I am getting... (2 Replies)
Discussion started by: jagdish.machhi@
2 Replies

9. IP Networking

snmptrap.conf file

Hi I tried a lot bt could not configure snmptrapd.conf... Can any one tell me the steps or give me the configured snmptrapd.conf file?? Its really important..Plz help me.. Thanx (0 Replies)
Discussion started by: swapna_me
0 Replies

10. UNIX for Advanced & Expert Users

Linux file corresponding to HP-UX inetd.conf

Hi!!, I have been working on a HP UX box all these days.. For adding a user defined service, I used to put an entry for this service corresponing to a port number in /etc/services. These services were then defined in inetd.conf. Now I have moved to Mandrake linux. I can find a file named... (2 Replies)
Discussion started by: jyotipg
2 Replies
Login or Register to Ask a Question