Sponsored Content
Full Discussion: A script need help
Top Forums Shell Programming and Scripting A script need help Post 303039361 by green_k on Wednesday 2nd of October 2019 12:08:26 AM
Old 10-02-2019
Quote:
Originally Posted by Yoda
Here is one approach using awk:-
Code:
awk -F= '
        /section/ {
                sc = $1
                S[sc]
                next
        }
        /^VALUE/ {
                A[sc FS $1] = $0
        }
        END {
                for ( k in S )
                        print k, A[k FS "VALUE1"] ? A[k FS "VALUE1"] : "MISSING", A[k FS "VALUE2"] ? A[k FS "VALUE2"] : "MISSING", A[k FS "VALUE3"] ? A[k FS "VALUE3"] : "MISSING"
        }
' file

thanks Yoda for your quick response. the code work with my sample data. it is my bad I didn't provide sample data correctly. the value1 , value2 and value3 don't have any relation. for example: CITY, REGION, STREET. I updated my post.

--- Post updated at 12:08 AM ---

Quote:
Originally Posted by Chubler_XL
And another awk approach:

Code:
awk -v want="VALUE1,VALUE2,VALUE3" -F'[=\\][]' '
function prnsection(i) {
   if(length(section)) {
     printf "%s",section;
     for(i=1;i in keypos;i++) {
       printf " %s", keys[keypos[i]]
       keys[keypos[i]]="MISSING"
     }
     printf "\n"
   }
}
BEGIN {
   for(i=split(want, keypos, ",");i;i--) {
       keys[keypos[i]]="MISSING";
   }
}
NF>2 { prnsection(); section=$0 }
$1 in keys { keys[$1]=$0 };
END { prnsection() }' infile

thanks Chubler_XL for you quick response, the code works as I expected.

Last edited by green_k; 10-02-2019 at 01:15 AM..
 

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

2. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

5. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
Tie::iCal(3pm)						User Contributed Perl Documentation					    Tie::iCal(3pm)

NAME
Tie::iCal - Tie iCal files to Perl hashes. VERSION
This document describes version 0.14 released 1st September 2006. SYNOPSIS
use Tie::iCal; tie %my_events, 'Tie::iCal', "mycalendar.ics" or die "Failed to tie file! "; tie %your_events, 'Tie::iCal', "yourcalendar.ics" or die "Failed to tie file! "; $my_events{"A-NEW-UNIQUE-ID"} = [ 'VEVENT', { 'SUMMARY' => 'Bastille Day Party', 'DTSTAMP' => '19970714T170000Z', 'DTEND' => '19970715T035959Z', } ]; tie %our_events, 'Tie::iCal', "ourcalendar.ics" or die "Failed to tie file! "; # assuming %my_events and %your_events # have no common keys (unless that's your intention) # while (my($uid,$event) = each(%my_events)) { $our_events{$uid} = $event; } while (my($uid,$event) = each(%your_events)) { $our_events{$uid} = $event; } untie %our_events; untie %your_events; untie %my_events; DEPENDENCIES
Tie::File DESCRIPTION
Tie::iCal represents an RFC2445 iCalendar file as a Perl hash. Each key in the hash represents an iCalendar component like VEVENT, VTODO or VJOURNAL. Each component in the file must have a unique UID property as specified in the RFC 2445. A file containing non-unique UIDs can be converted to have only unique UIDs (see samples/uniquify.pl). The module makes very little effort in understanding what each iCalendar property means and concentrates on the format of the iCalendar file only. FILE LOCKING
The Tie::iCal object returned by tie can also be used to access the underlying Tie::File object. This is accessible via the 'A' class variable. This may be useful for file locking. my $ical = tie %events, 'Tie::iCal', "mycalendar.ics"; $ical->{A}->flock; DATES
The iCalendar specification uses a special format for dates. This module makes no effort in trying to interpret dates in this format. You should look at the Date::ICal module that can convert between Unix epoch dates and iCalendar date strings. How Tie::iCal interprets iCal files Tie::iCal interprets files by mapping iCal components into Perl hash keys and iCal content lines into various Perl arrays and hashes. Components An iCal component such as VEVENT, VTODO or VJOURNAL maps to a hash key:- BEGIN:VEVENT UID:a_unique_uid NAME1:VALUE1 .. END:VEVENT corresponds to $events{'a_unique_uid'} = ['VEVENT', {'NAME1' => 'VALUE1'}] Subcomponents An iCal subcomponent such as VALARM maps to a list of hash keys:- BEGIN:VALARM TRIGGER;VALUE=DURATION:-PT1S TRIGGER;VALUE=DURATION:-PT1S END:VALARM BEGIN:VALARM X-TIE-ICAL;VALUE=ANOTHER:HERE X-TIE-ICAL:HERE2 X-TIE-ICAL-NAME:HERE2 END:VALARM corresponds to 'VALARM' => [ { 'TRIGGER' => [ [{'VALUE' => 'DURATION'},'-PT1S'], [{'VALUE' => 'DURATION'},'-PT1S'] ] }, { 'X-TIE-ICAL' => [ [{'VALUE' => 'ANOTHER'},'HERE'], ['HERE2'] ], 'X-TIE-ICAL-NAME' => 'HERE2' } ] To see how individual content lines are formed see below. Content Lines Once unfolded, a content line may look like:- NAME;PARAM1=PVAL1;PARAM2=PVAL2;...:VALUE1,VALUE2,... having an equivalent perl data structure like: - 'NAME' => [{'PARAM1'=>'PVAL1', 'PARAM2'=>'PVAL2', ..}, 'VALUE1', 'VALUE2', ..] or NAME:VALUE1,VALUE2,... having an equivalent perl data structure like: - 'NAME' => ['VALUE1', 'VALUE2', ..] or NAME:VALUE having an equivalent perl data structure like: - 'NAME' => 'VALUE' An blank value is mapped from NAME: to 'NAME' => '' Multiple contentlines with same name, i.e. FREEBUSY, ATTENDEE:- NAME;PARAM10=PVAL10;PARAM20=PVAL20;...:VALUE10,VALUE20,... NAME;PARAM11=PVAL11;PARAM21=PVAL21;...:VALUE11,VALUE21,... ... having an equivalent perl data structure like: - 'NAME' => [ [{'PARAM10'=>'PVAL10', 'PARAM20'=>'PVAL20', ..}, 'VALUE10', 'VALUE20', ..], [{'PARAM11'=>'PVAL11', 'PARAM21'=>'PVAL21', ..}, 'VALUE11', 'VALUE21', ..], ... ] or NAME:VALUE10,VALUE20,... NAME:VALUE11,VALUE21,... ... having an equivalent perl data structure like: - 'NAME' => [ ['VALUE10', 'VALUE20', ..], ['VALUE11', 'VALUE21', ..], ... ] or in a mixed form, i.e. NAME:VALUE10,VALUE20,... NAME;PARAM11=PVAL11;PARAM21=PVAL21:VALUE11,VALUE21,... NAME:VALUE12,VALUE22,... ... having an equivalent perl data structure like: - 'NAME' => [ ['VALUE10', 'VALUE20', ..], [{'PARAM11'=>'PVAL11', 'PARAM21'=>'PVAL21', ..}, 'VALUE11', 'VALUE21', ..], ['VALUE12', 'VALUE22', ..], ... ] BUGS
Property names are assumed not to be folded, i.e. DESCR IPTION:blah blah.. RRULE property does not support parameters. Property names that begin with UID can potentially confuse this module. Subcomponents such as VALARM must exist after any UID property. Deleting events individually may leave non-RFC2445 compliant empty VCALENDAR objects. AUTHOR
Blair Sutton, <mailto:bsdz@cpan.org>, <http://www.numeninest.com/> COPYRIGHT
Copyright (c) 2006 Blair Sutton. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl, Tie::File, Date::ICal perl v5.12.4 2011-11-11 Tie::iCal(3pm)
All times are GMT -4. The time now is 06:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy