Sponsored Content
Full Discussion: A script need help
Top Forums Shell Programming and Scripting A script need help Post 303039385 by green_k on Wednesday 2nd of October 2019 07:24:30 PM
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

Hi Yoda,
I modify this code to match multiple pattern, it works fine. I have below question.
1. what's purpose of FS in this array. A[sc FS $1]. my understanding is when match find, then assign $0 to array A with index "section and $1".
2. is it possible using pattern match at below code value1, value2? in the file, this value are not same. for example:
there are some value like below: in this case, we consider these two city are same.
Code:
[section_abc]
CITY_1=ABC
[section_cde]
CITY_new=xyz

Code:
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"

 

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
Test::WWW::Declare(3pm) 				User Contributed Perl Documentation				   Test::WWW::Declare(3pm)

NAME
Test::WWW::Declare - declarative testing for your web app SYNOPSIS
use Test::WWW::Declare tests => 3; use Your::Web::App::Test; Your::Web::App::Test->start_server; session 'testuser' => run { flow 'log in and out' => check { flow 'log in' => check { get 'http://localhost/'; fill form 'login' => { username => 'testuser', password => 'drowssap', }; content should contain 'log out'; }; flow 'log out' => check { get 'http://localhost/'; click href 'log out'; }; }; }; DESCRIPTION
Often in web apps, tests are very dependent on the state set up by previous tests. If one test fails (e.g. "follow the link to the admin page") then it's likely there will be many more failures. This module aims to alleviate this problem, as well as provide a nicer interface to Test::WWW::Mechanize. The central idea is that of "flow". Each flow is a sequence of commands ("fill in this form") and assertions ("content should contain 'testuser'"). If any of these commands or assertions fail then the flow is aborted. Only that one failure is reported to the test harness and user. Flows may also contain other flows. If an inner flow fails, then the outer flow fails as well. FLOWS AND SESSIONS
session NAME => run { CODE } Sessions are a way of associating a set of flows with a WWW::Mechanize instance. A session is mostly equivalent with a user interacting with your web app. Within a session, every command ("get", "click link", etc) is operating on that session's WWW::Mechanize instance. You may have multiple sessions in one test file. Two sessions with the same name are in fact the same session. This lets you write code like the following, simplified slightly: session 'first user' => run { get "$URL/give?task=1&victim=other"; session 'other user' => run { get "$URL/tasks"; content should match qr/task 1/; # this is the same session/mech as the outermost 'first user' session 'first user' => run { get "$URL/tasks"; content shouldnt match qr/task 1/; }; }; }; flow NAME => check { CODE } A flow encompasses a single test. As described above, each flow is a sequence of commands, assertions, and other flows. If any of the components of a flow fail, the rest of the flow is aborted and one or more test failures are reported to the test harness. COMMANDS
get URL click button click href follow_link fill form NAME => {FIELD1 => VALUE1, FIELD2 => VALUE2} ASSERTIONS
Every assertion has two parts: a subject and a verb. SUBJECTS content title url VERBS should(nt) (caselessly) match REGEX should(nt) (caselessly) contain STRING should(nt) (caselessly) lack STRING should(nt) (caselessly) equal STRING SUBCLASSING
One of the goals of this module is to let you subclass it to provide extra features, such as automatically logging in a user each time a session is created. CAVEATS
If you fail any tests, then the actual number of tests run may be fewer than you have in your file. This is because when a flow fails, it immediately aborts the rest of its body (which may include other flows). So if you're setting the number of tests based on how many ran, make sure that all tests passed. BUGS
Hopefully few. We'd like to know about any of them. Please report them to "bug-test-www-declare@rt.cpan.org". SEE ALSO
Test::WWW::Mechanize, Jifty. MAINTAINER
Shawn M Moore "<sartak@bestpractical.com>" ORIGINAL AUTHOR
Jesse Vincent "<jesse@bestpractical.com>" COPYRIGHT
Copyright 2007-2008 Best Practical Solutions, LLC This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2008-10-12 Test::WWW::Declare(3pm)
All times are GMT -4. The time now is 01:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy