Sponsored Content
Top Forums Shell Programming and Scripting Problem with awk and if statement Post 302255793 by radoulov on Friday 7th of November 2008 06:01:06 AM
Old 11-07-2008
Yes,
while reading the first input file build an associative array ref keyed by the first field with values from the second one. You should add more control here: I'm assuming that the second field is always present and that it does not contain special (for the shell) characters.
While reading the second input file check if the first 3 characters match any ref key, if yes: checks if a directory with that name already exists, if not creates it. Then prints the current record in a file named as the second input filename in that directory; if not: does the same for the others directory.

Hope this helps.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

if statement problem

I keep getting an error at line 21, it doesn't like my if statement. Previously I have tried using (( )), but still get errors. The current error is that server_busy is not found. This is the script: #! /bin/ksh server_busy="na" for file in $1 $2 $3 $4 $5 $6 do echo " ${file}\t\c" ... (1 Reply)
Discussion started by: coughlin74
1 Replies

2. UNIX for Dummies Questions & Answers

if statement problem

hi all. i just have a very small problem. i have a menu of 7 choices. i want an if statement so that if the user chooses anything except inside the 1 to 7 range, i can handle the error for it. i tried this: if ] then ....... fi (but it dont work) ...any suggestions? ... (4 Replies)
Discussion started by: djt0506
4 Replies

3. UNIX for Dummies Questions & Answers

if statement problem

See https://www.unix.com/shell-programming-scripting/96846-if-statement-problem.html (0 Replies)
Discussion started by: f_o_555
0 Replies

4. Shell Programming and Scripting

if statement problem

Hi I have a bash script like this if then echo "A" else echo "B" fi $1 is something like 02350 (there is always a trailing '0') and I would like to have an if based on the value of the digits after the 0. Can anybody help? Thanks, Sarah (3 Replies)
Discussion started by: f_o_555
3 Replies

5. Shell Programming and Scripting

problem with if/while statement

I'm trying to have the script check if a file has data or not, and then process it accordingly. If the file is empty, I want it to return "nothing to do", if not, I want it to process the file line by line. This is what I have so far, but it always returns "nothing to do", even if the file is not... (4 Replies)
Discussion started by: ddrew78
4 Replies

6. UNIX for Dummies Questions & Answers

Having problem with if statement

Could someone help me out with this if statement? It's supposed to get a person's website, but it isn't working when I run it. website="" echo "Would you like to enter a website? Enter Yes/No" read choice if then while do echo "Please enter a website:"; read... (4 Replies)
Discussion started by: Sotau
4 Replies

7. Shell Programming and Scripting

if statement problem

Writing my script and I'm banging my head on the desk right now ... My biggest problem is the 3rd IF statement where I check if the username exists. Doing the grep command on it's own in the shell gives me a 1 or 0 value. Running the script, it always returns a false value (runs the ELSE... (4 Replies)
Discussion started by: ADay2Long
4 Replies

8. Shell Programming and Scripting

Awk or If/statement Calculation Problem

#!/bin/sh CURRENTSTATE=2 CSVCSTATE=2 LASTSTATECHANGE=8 CSVCSTATEAGE=5 if (($CURRENTSTATE==$CSVCSTATE))&&(($LASTSTATECHANGE>=$CSVCSTATEAGE)) echo GREAT fi returns: ./aff: line 12: syntax error near unexpected token `fi' ./aff: line 12: `fi' what am i doing wrong here? (6 Replies)
Discussion started by: SkySmart
6 Replies

9. Shell Programming and Scripting

Awk/sed problem to write Db insertion statement

Hi There, I am trying to load data from a csv file into a DB during our DB migration phase. I am successfully able export all data into a .csv file but those have to rewritten in terms insert statement which will allow for further population of same data in different DB My exiting csv record... (6 Replies)
Discussion started by: bhaskar_m
6 Replies

10. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies
join-dctrl(1)						      General Commands Manual						     join-dctrl(1)

NAME
join-dctrl - perform relational join on data in dctrl format SYNOPSIS
join-dctrl [ options ] filename filename join-dctrl --version join-dctrl --help DESCRIPTION
join-dctrl performs a relational join operation on data given to it in Debian control file format. A join field must be specified using either the switches -1 and -2 or the switch -j. Conceptually, the program creates all ordered pairs of records that can be formed by having a record from the first file as the first member of the pair and having a record from the second file as the second member of the pair; and then it deletes all such pairs where the join fields are not equal. Effectively, each of the input files is treated as a relational database table. Every input file must be in ascending order on its join field; this allows the program to work fast. The sort-dctrl(1) program can be used to make it so. OPTIONS
-1 field, --1st-join-field=field Specify the join field of the first input file. -2 field, --2nd-join-field=field Specify the join field of the second input file. -j field, --join-field=field Specify a common join field for all files. -a fileno, --unpairable-from=fileno Specify that unmatched paragraphs from the first (if 1 is given) or the second (if 2 is given) file are printed. -o fieldspec, --output-fields=fieldspec Specify which fields are included in the output. Fields are separated by commas (more than one -o option can be used, too). Each field is specified in the format fileno.field in which fileno is the ordinal number of the input file from which the field is drawn (either 1 or 2), and field gives the name of the field to use. As a special case, simple 0 can be used instead of fileno.field to refer to the common value of the join fields. The name of the field (not including the file number) is used in the output as the name of the field. However, a different name for output purposes can be specified by suffixing the field specification by a colon and the preferred visible name. For example, the option -o 0,1.Version:Old-Version,2.Version specifies that the first field in any output record should be the join field, the second field should be Old-Version drawing its data from the Version field of the first input file, and the third field should be Version drawing its data from the field with the same name in the second input file, and these are the only fields in an output record. If no -o option is given, all fields of all the records being joined are included in the output. -l level, --errorlevel=level Set log level to level. level is one of fatal, important, informational and debug, but the last may not be available, depending on the compile-time options. These categories are given here in order; every message that is emitted when fatal is in effect, will be emitted in the important error level, and so on. The default is important. -V, --version Print out version information. -C, --copying Print out the copyright license. This produces much output; be sure to redirect or pipe it somewhere (such as your favourite pager). -h, --help Print out a help summary. OPERANDS
join-dctrl will treat each file named on the command line as a relational database table. A file called - represents the program's stan- dard input stream. Currently, exactly two files must be named. STDIN
The standard input stream may be used as input as specified above in the OPERANDS section. INPUT FILES
All input to join-dctrl is in the format of a Debian control file. A Debian control (dctrl) file is a semistructured single-table database stored in a machine-parseable text file. Such a database consists of a set of records; each record is a mapping from field names to field content. Textually, records are separated by empty lines, while each field is encoded as one or more nonempty lines inside a record. A field starts with its name, followed by a colon, followed by the field content. The colon must reside on the first line of the field, and the first line must start with no whitespace. Subsequent lines, in contrast, always start with linear whitespace (one or more space or tab characters). Each input file must be in the ascending order of its join field. ENVIRONMENT VARIABLES
The standard locale environment, specifically its character set setting, affects the interpretation of input and output as character streams. ASYNCHRONOUS EVENTS
Standard UNIX signals have their usual meaning. STDOUT
All output is sent to the standard output stream. The output is in the format of a Debian control file, described above in the INPUT FILES section. The output will be in the ascending order of the join field, if that field is included in the output. OUTPUT FILES
There are no output files. EXIT STATUS
This utility exits with 0 when successful. It uses a nonzero exit code inconsistently when an error is noticed (this is a bug). CONSEQUENCES OF ERRORS
In case of errors in the input, the output will be partially or completely garbage. In case of errors in invocation, the program will refuse to function. EXAMPLES
Suppose that a file containing data about binary packages for the AMD64 architecture contained in the Debian squeeze (6.0) release, section main, is in the current directory and named Packages. Suppose that we are currently on a Debian system. Suppose further that the current directory does not contain files named stat and pkg. The following commands gives, for each package currently installed and available in Debian squeeze (6.0), its currently installed version (as Old-Version) and the version in squeeze (as New-Version): $ sort-dctrl -kPackage /var/lib/dpkg/status > stat $ sort-dctrl -kPackage Packages > pkg $ join-dctrl -j Package -o 0,1.Version:Old-Version,2.Version:New-Version stat pkg AUTHOR
The join-dctrl program and this manual page were written by Antti-Juhani Kaijanaho. SEE ALSO
grep-dctrl(1), sort-dctrl(1), tbl-dctrl(1) join-dctrl(1)
All times are GMT -4. The time now is 05:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy