Sponsored Content
Top Forums Shell Programming and Scripting awk string comparison unterminated quoted string andrule of thumb Post 302957322 by deadyetagain on Friday 9th of October 2015 07:32:04 AM
Old 10-09-2015
awk string comparison unterminated quoted string andrule of thumb

I have the logic below to look up for matches within the columns between the two files with awk.

In the if statement is where the string comparison is attempted with ==
The issue seems to be with the operands, as
1. when " '${SECTOR[$i]}' " -- double quote followed by single quote -- awk matches all strings without space but cannot strings with space
ex. find matches when Financials==Financials
but cannot when Consumer Cyc == Consumer Cyc and produced unterminated string error

awk: cmd. line:1: if ( $1=="GB" && $3=="Consumer
awk: cmd. line:1: ^ unterminated string

2. when ' "${SECTOR[$i]}" ' -- single quote followed by double quote -- awk matches all strings with space but cannot strings without space
ex. find matches when Consumer Cyc == Consumer Cyc
but cannot when Financials == Financials

no error however no match and prints out sample outputs where should

Any comment is appreciated

Code:
#! /bin/sh
#! /bin/bash
#########################################

line=`wc -l LE_Sample.csv | awk '{print $1}'`
for (( i=2; i<=$line; i++ ))
do

COUNTRY[$i]=`awk -F"," ' (NR=='$i'){ print $4 }' ./LE_Sample.csv`
REGION[$i]=`awk -F"," ' (NR=='$i'){ print $5 }' ./LE_Sample.csv`
SECTOR[$i]=`awk -F"," ' (NR=='$i'){ print $6 }' ./LE_Sample.csv`
MKTCAP[$i]=`awk -F"," ' (NR=='$i'){ print $7 }' ./LE_Sample.csv`

awk -F"," '{
   if ( $1=="'${COUNTRY[$i]}'" && $3=="'${SECTOR[$i]}'" &&  $4 <= '${MKTCAP[$i]}' && $5 >= '${MKTCAP[$i]}' )
  {
        print NR
        print $1
        print $3
        print $4
        print $5
        print '${MKTCAP[$i]}'
  }
}' ./CCModels.csv

done


Last edited by vbe; 10-09-2015 at 08:33 AM.. Reason: code tags please not ICODE thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String Comparison between two files using awk

I have two files with field seperator as "~". File A: 12~13~14~15 File B: 22~22~32~11 i want to calculate the difference between two files and than calculate the percentage difference and output it to a new file. How do i do this using awk. Also please suggest GOOD awk tutorials. Thank... (7 Replies)
Discussion started by: rudoraj
7 Replies

2. UNIX for Dummies Questions & Answers

Unterminated string

While running a shell script i am getting this warning but the script is working fine.while running the blocks of the scripts individually its running fine.But while pasting it combinedly this is the warning..wat may be the reason behind this and how to resolve it (3 Replies)
Discussion started by: dr46014
3 Replies

3. Shell Programming and Scripting

how to delete blanks inside a quoted string

Hi I need to update a string inside a file which looks like the following: PX_LIST=" 4119 2390 2294 2776 2897 4099 " Is there a way to get rid of the blanks after the first quote mark and before the last quote mark. This needs to be done ONLY for the string named PX_LIST (there are some... (4 Replies)
Discussion started by: aoussenko
4 Replies

4. Shell Programming and Scripting

Syntax error: Unterminated quoted string

I keep having problems when exicuting this file. It always gives me the error message "36: Syntax error: Unterminated quoted string" If someone could help me edit this it would be much appreciated. #!/bin/sh # # This will continue adding numbers # untill the total is greater than 1,000 #... (5 Replies)
Discussion started by: evilSerph
5 Replies

5. Shell Programming and Scripting

Unterminated quoted string

Hello! I wroted a little script that should check for new updates on a server and get them if any. The problem is, every time I run it with sh, I'm getting an "script: 20: Syntax error: Unterminated quoted string" error! The problem is, there isn't any "unterminated quoted string" in my script:... (2 Replies)
Discussion started by: al0x
2 Replies

6. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. Homework & Coursework Questions

passing letters from an array into a string for string comparison

attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now. ##I have an array $wordString that initializes to a string of dashes ##reflecting the number of letters in $theWord ##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies

8. Shell Programming and Scripting

AWK string comparison

Hey guys.. New in linux scripting and need some help on some scripting with history command. I managed to export the command history into a file and now i'm trying to select from that file some specific commands that were made in a certain period. Here's what i got so far echo -n... (2 Replies)
Discussion started by: mishu_cgm
2 Replies

9. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

10. UNIX for Dummies Questions & Answers

Getting " Unterminated quoted string"

Hi Guys, When I am executing the script #! /bin/bash SARBACKUPS=/home/pradeep/sarBackups cd /var/log/sysstat ls -1t sar* | while read SARNAME do cp -p "$SARNAME" $( echo "$SARBACKUPS"/"$HOSTNAME"_"$SARNAME"_"`date +"%Y%m%d`.bkup ) done I am getting final.sh: 1: Syntax... (3 Replies)
Discussion started by: Pradeep_1990
3 Replies
dat_evd_query(3DAT)				     Direct Access Transport Library Functions				       dat_evd_query(3DAT)

NAME
dat_evd_query - provide parameters of the Event Dispatcher, SYNOPSIS
cc [ flag... ] file... -ldat [ library... ] #include <dat/udat.h> DAT_RETURN dat_evd_query ( IN DAT_EVD_HANDLE evd_handle, IN DAT_EVD_PARAM_MASK evd_param_mask, OUT DAT_EVD_PARAM *evd_param ) PARAMETERS
evd_handle Handle for an instance of Event Dispatcher. evd_param_mask Mask for EVD parameters evd_param Pointer to a Consumer-allocated structure that the Provider fills for Consumer-requested parameters. DESCRIPTION
The dat_evd_query() function provides to the Consumer parameters of the Event Dispatcher, including the state of the EVD (enabled/dis- abled). The Consumer passes in a pointer to the Consumer-allocated structures for EVD parameters that the Provider fills. The evd_param_mask parameter allows Consumers to specify which parameters to query. The Provider returns values for evd_param_mask requested parameters. The Provider can return values for any of the other parameters. RETURN VALUES
DAT_SUCCESS The operation was successful. DAT_INVALID_HANDLE The evd_handle parameter is invalid. DAT_INVALID_PARAMETER The evd_param_mask parameter is invalid. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard: uDAPL, 1.1, 1.2 | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
libdat(3LIB), attributes(5) SunOS 5.10 16 Jul 2004 dat_evd_query(3DAT)
All times are GMT -4. The time now is 01:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy