Sponsored Content
Top Forums Shell Programming and Scripting Search/grep on row and column wise Post 302947716 by calredd on Saturday 20th of June 2015 11:45:19 PM
Old 06-21-2015
Quote:
Originally Posted by Don Cragun
None of your examples match your sample data.

You don't have a field named CITY; you have a field named CITY followed by eight spaces. If you try to look for a value in the CITY field, it should fail because there is no CItY field.

With a comma separated data file, you don't have a city name of CHICAGO; you have a city name of CHICAGO followed by three spaces, and you don't have a city name of NEWARK; you have a city name of NEWARK followed by four spaces.

And, if someone entered the keys, CHICAGO followed by three spaces and STATE they should get IL followed by 7 spaces; not just IL.

And, if you have columns in the order CITY,STATE,COUNTY,STATE (which you said is possible) and the user gives keys NEW_YORK and STATE are you supposed to return the value in column 2, column 4, or both???

How are the keys supplied to your script?

What operating system and shell are you using?

What have you tried so far?

Is this a homework assignment?



Sorry for the confusion but there are no space in the data. I only put spaces to make it easier to understand. Here's how the data will appear:

Code:
CITY,COUNTY,STATE,COUNTRY
NEW_YORK,NYC,NY,USA
NEWARK,ESSEX,NJ,USA
CHICAGO,COOK,IL,USA
SEATTLE,MINER,WA,USA

Q. How are the keys supplied to your script? A value from first column and a column name
Ex: NEWARK & STATE, SEATTLE & COUNTRY, NEWARK & COUNTY

Q. What operating system and shell are you using? LINUX and ksh

So far, I have tried doing a egrep on both CITY and the value from the first row (ex: NEW_YORK or CHICAGO) to get two rows. But after that, I need to narrow down the value to a specific column name which can be either COUNTY or STATE or COUNTRY and here's where I am struck.
Moderator's Comments:
Mod Comment If you don't start using CODE tags (as required by forum rules) you may be banned from The UNIX & Linux Forums.


No, this is not a homework but rather I need to mine a metadata file to narrow down the value to a specific row and column.

Hope my explantion helps.

Last edited by Don Cragun; 06-21-2015 at 01:16 AM.. Reason: Add CODE tags, again.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix addition ( Row wise)

Hi I have a file like a,1 b,2 d,3 a,2 b,3 c,7 Result Desired: a,3 b,5 d,3 c,7 i.e on the bases of 1st field the addition is done of the 2nd field and result printed out. (3 Replies)
Discussion started by: gauravgoel
3 Replies

2. Shell Programming and Scripting

Row to column converter using Awk or grep?

Hello, Can someone please help me on this.:confused: I have a file which has more than 1 million lines (XML file). What I need is: Search for "abcd" in the input file > output the result into a output.txt (colloum1) Search for "efghi" in the input file > output the result in to... (3 Replies)
Discussion started by: Needhelp2
3 Replies

3. Shell Programming and Scripting

Search a file column wise and delete it

i have a file which has a column that is unique i am intending to serach it and if it is there to remove the row. the file looks like ROLLNO,NAME ,SUB1,SUB2,SUB3,TOTAL,PERCENTAGE,RESULT 15 ,rig ,34 ,56 ,87 ,177 ,59 % ,PASS 23 ,wel ,45 ,76 ,56 ,177 ,59 % ... (0 Replies)
Discussion started by: gotam
0 Replies

4. Shell Programming and Scripting

Search a file column wise and delete it

Scottn, m really sorry but i have not got my answer yet. my concern is how to delete the row !!! i have a file which has a column that is unique i am intending to serach it and if it is there to remove the row. the file looks like ROLLNO,NAME ,SUB1,SUB2,SUB3,TOTAL,PERCENTAGE,RESULT... (9 Replies)
Discussion started by: gotam
9 Replies

5. Shell Programming and Scripting

awk-gsub on column-wise on each row

awk '{ gsub(/....=/,""); print }' want.dat >final.dat the above awk command which removes all the chars before and including '=' on the entire row. --thats what it meant be.:) but i need to remove text on column-wise on each row. many thanks, EM ---------- Post updated at 10:00 AM... (4 Replies)
Discussion started by: elamurugu
4 Replies

6. Shell Programming and Scripting

search column and delete row if greater than value

Hi, as the title states i need to find a way to search a column for values great than 1000, and if it is, then delete that row. An example 1 7.021 6.967 116.019 4 U 6.980E+07 0.000E+00 e 0 0 0 0 2 8.292 7.908 118.063 3 U 1.440E+07 0.000E+00 e 0 821 814 ... (3 Replies)
Discussion started by: olifu02
3 Replies

7. Shell Programming and Scripting

calculating row-wise standard deviation using awk

Hi, I have a file containing 100,000 rows-by-120 columns and I need to compute for the standard deviation for each row. Any idea on how to calculate row-wise standard deviation using awk? My sample data looks like this: input data: 23 35 12 25 16 17 18 19 29 12 12 26 15 14 15 23 12 12... (2 Replies)
Discussion started by: ida1215
2 Replies

8. Shell Programming and Scripting

Grep the column for a row

I have a problem caught and need to discuss with all you guys. I have a file containing a rows which are separated by “~” For eg. Server~321~UP~Linux~Member 121213~5778~Down~Unix~Provider I want to use the grep which search the row on the basis of columns like the grep... (6 Replies)
Discussion started by: adisky123
6 Replies

9. UNIX for Dummies Questions & Answers

Print row wise

Hi Help, I have an I/p, which looks like --- FF GG HH I want the o/p to be like --- FF GG HH. How we can do that? Thanks (7 Replies)
Discussion started by: Indra2011
7 Replies

10. Shell Programming and Scripting

Search string in multiple files and display column wise

I have 3 files. Each of those files have the same number of records, however certain records have different values. I would like to grep the field in ALL 3 files and display the output with only the differences in column wise and if possible line number File1 Name = Joe Age = 33... (3 Replies)
Discussion started by: sidnow
3 Replies
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy