row Comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting row Comparison
# 1  
Old 03-04-2011
row Comparison

Quote:
I have to compare first row in a file with some string.

Temp_var=`echo '"CUST_INFO","CUST_NAME","CUST_AGE"'`
head_file=`head -1 customer_file.txt`
Total_col_count=`awk -F"," '{print NF}' customer_file.txt|sort -u`

Code:
 
if [ $Total_col_count = 10 -a $Temp_var = $head_file ]
then 
echo "matched"
else "not matched"
fi

i am getting the below erroran i have searched in the fourms but did not find the related. Any help greatly appricated.

temp.sh[34]: -: 0403-012 A test command parameter is not valid.
# 2  
Old 03-04-2011
Code:
if [ $Total_col_count -eq 10 -a $Temp_var == $head_file ]

# 3  
Old 03-04-2011
Thanks for the swift response but still facing the same. As I am guessing the row having double quotes that's way it is comparing. still unable to find the root cause.

error message
0403-012 A test command parameter is not valid.

Code:
 
Temp_var=`echo '"CUST_INFO","CUST_NAME","CUST_AGE"'`
head_file=`head -1 customer_file.txt`
Total_col_count=`awk -F"," '{print NF}' customer_file.txt|sort -u`
if [ $Total_col_count  -eq 10 -a $Temp_var  ==  $head_file ]
then 
echo "matched"
else "not matched"
fi

# 4  
Old 03-04-2011
More chances that Total_col_count variable to hold more than one value in your case. So the if condition fails as your comparing it with single value 10. Print the value of Total_col_count and check before going for if condition to make sure it holds only single value and not multiple.
# 5  
Old 03-04-2011
Quote:
Hi,

I am getting single value for that column.

Used echo on each output value, i am getting only one valie at a time.
i am not understanding the nature of if condition if you have row comparision with in the double quotes. still i am getting the same error message.

Any help greatly appriciated.

Thanks
# 6  
Old 03-04-2011
Ok.So your sure that the file customer_file.txt contains only one line.. Or many lines with same number of columns..? One little bug is that there is no echo statement in the else part.
Code:
if [ $Total_col_count  -eq 10 -a $Temp_var  ==  $head_file ]
then 
        echo "matched"
else 
        echo "not matched"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

This is a question that is related to one I had last August when I was trying to sort/merge two files by millsecond time column (in this case column 6). The script (below) that helped me last august by RudiC solved the puzzle of sorting/merging two files by time, except it gets lost when the... (0 Replies)
Discussion started by: aachave1
0 Replies

2. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

3. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

My original files are like this below and I distinguish them from the AP_ID (file1 has 572 and file2 has 544). Also, the header on file1 has “G_” pre-pended. NOTE: these are only snippets of very large files and much of the data is not present here. Original File 1: ... (36 Replies)
Discussion started by: aachave1
36 Replies

4. Shell Programming and Scripting

Add Row from First Row (Split Row)

HI Guys, I have Below Input :- RepigA_hteis522 ReptCfiEtrBsCll_aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 RepigA ReptCfiEtrBsCll hteis522 aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 Split Data in two first row... (2 Replies)
Discussion started by: pareshkp
2 Replies

5. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

6. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

7. Shell Programming and Scripting

How to do row comparison in shell script

Hi, I need help on doing the below thing in shell script. I have a file with millions of rows called "abc.txt". i have another file with millions of rows called "xyz.txt". I would like to do the below operation. Open the abc.txt, read the first line, do some operations on the column... (2 Replies)
Discussion started by: informsrini
2 Replies

8. Shell Programming and Scripting

Sequential comparison (one row with file and so on)

Dear linux experts, I'd like to ask for your support, I've read some posts in this forum about files comparison but haven't found what I'm looking for. I need to create a sequential script to compare row-by-row one file with 34 similar files but without success so far. This is what I get: ... (2 Replies)
Discussion started by: Gery
2 Replies

9. Shell Programming and Scripting

consecutive row comparison in awk (?)

hi, I'm totally new to this forum and to awk. I have what I thought was a simple problem, but I can't get anything to work. Here is an example input file: 3.85 4018.4 3.9 4068.4 3.95 4082.9 4 4099.7 # Property:.......etc. 0 4733.3 0.05 4659.7 0.1 4585.6 0.15 4466.2 Two... (2 Replies)
Discussion started by: ogga
2 Replies

10. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question