Searching with a value to get an entire row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching with a value to get an entire row
# 1  
Old 04-24-2010
Searching with a value to get an entire row

i have the file where the 1st column is unique value.
ROLLNO,NAME ,SUB1,SUB2,SUB3,TOTAL,PERCENTAGE,RESULT
Code:
15     ,rig   ,34  ,56  ,87  ,177  ,59 %         ,PASS
23     ,wel   ,45  ,76  ,56  ,177  ,59 %         ,PASS
23     ,rew   ,23  ,45  ,67  ,135  ,45 %       ,THIRD
45     ,ramu   ,24  ,78  ,45  ,147  ,49 %       ,FAIL

i want to search the file with a given rollnum and if that prsent in the 1st column..i want that entire row to be output

i tried

Code:
cut -f1 -d "," filename | sed -ne '/"$rollnum"/p'

but getting only the rollnum if that is present but not the entire row.
plz help !!

Last edited by Scott; 04-24-2010 at 01:37 PM.. Reason: Added more code tags
# 2  
Old 04-24-2010
Try:
Code:
grep "^$rollnum " file

# 3  
Old 04-24-2010
ye.. thanks franklin..
this will work in this case..
but how about if the uniq column is the 2nd or 3rd column in the file.

plz help !!
# 4  
Old 04-24-2010
You could try:
Code:
awk -F, '$1==r' r="$rollnum" infile

use e.g. $3 if you need to match the 3rd column
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script to fill the entire row of Excel file with color based on pattern match

Hi All , I have to write one Perl script in which I need to read one pre-existing xls and based on pattern match for one word in some cells of the XLS , I need to fill the entire row with one color of that matched cell and write the content to another excel Please find the below stated... (2 Replies)
Discussion started by: kshitij
2 Replies

2. 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

3. 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

4. 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

5. 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

6. Shell Programming and Scripting

Parsing out the entire row

I do have a big text file with the following format with 9 columns tab delimited. I would like to parse out the entire row if any of the columns 6, 7, 8 and 9 have non-zero numbers. Following is the input file 513741 C 1053 389 389 0 6 0 269 513742 A ... (2 Replies)
Discussion started by: Kanja
2 Replies

7. Shell Programming and Scripting

Searching for similar row(s) across multiple files

Hello Esteemed Members, I need to write a script to search for files that have one or more than one rows similar. Please note that there is no specific pattern that I am searching for. The rows can be different, I just need to find out two or more similar records in two or more files. There... (7 Replies)
Discussion started by: Yoodit
7 Replies

8. 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

9. Shell Programming and Scripting

Printing entire field, if at least one row is matching by AWK

Dear all, I have been trying to print an entire field, if the first line of the field is matching. For example, my input looks something like this. aaa ddd zzz 123 987 126 24 0.650 985 354 9864 0.32 0.333 4324 000 I am looking for a pattern,... (5 Replies)
Discussion started by: Chulamakuri
5 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