Parsing out the entire row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing out the entire row
# 1  
Old 02-13-2015
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

Code:
513741  C       1053    389     389     0       6       0       269
513742  A       1047    540     502     0       1       3       1
513743  T       1036    538     497     1       0       0       0
513744  G       1027    536     491     0       0       0       0
513745  T       1017    526     485     0       5       1       0
513746  G       1013    531     482     0       0       0       0
513747  G       995     519     475     1       0       0       0
513748  T       989     474     474     2       33      6       0
513749  T       981     511     469     0       1       0       0
513750  T       968     505     463     0       0       0       0
513751  A       957     496     456     0       1       1       3
513752  A       943     492     451     0       0       0       0
513753  T       927     479     445     1       2       0       0
513754  T       917     475     442     0       0       0       0
513755  C       905     468     436     1       0       0       0
513756  G       875     455     419     1       0       0       0
513757  A       852     448     403     0       1       0       0
513758  A       842     283     282     0       1       255     21

The desired output file is
Code:
513741  C       1053    389     389     0       6       0       269
513742  A       1047    540     502     0       1       3       1
513745  T       1017    526     485     0       5       1       0
513747  G       995     519     475     1       0       0       0
513748  T       989     474     474     2       33      6       0
513749  T       981     511     469     0       1       0       0
513751  A       957     496     456     0       1       1       3
513753  T       927     479     445     1       2       0       0
513755  C       905     468     436     1       0       0       0
513756  G       875     455     419     1       0       0       0
513757  A       852     448     403     0       1       0       0
513758  A       842     283     282     0       1       255     21

tried the following awk command
Code:
awk 'NR==FNR{a[$6]++;next}a[$6]>0' FS='t' file1 > Output

It would be great if I could get some help

---------- Post updated at 11:05 PM ---------- Previous update was at 11:03 PM ----------

Sorry for mistake in the format of the sample input file.

Code:
513741 C 1053 389 389 0 6 0 269
513742 A 1047 540 502 0 1 3 1
513743 T 1036 538 497 1 0 0 0
513744 G 1027 536 491 0 0 0 0
513745 T 1017 526 485 0 5 1 0
513746 G 1013 531 482 0 0 0 0
513747 G 995 519 475 1 0 0 0
513748 T 989 474 474 2 33 6 0
513749 T 981 511 469 0 1 0 0
513750 T 968 505 463 0 0 0 0
513751 A 957 496 456 0 1 1 3
513752 A 943 492 451 0 0 0 0
513753 T 927 479 445 1 2 0 0
513754 T 917 475 442 0 0 0 0
513755 C 905 468 436 1 0 0 0
513756 G 875 455 419 1 0 0 0
513757 A 852 448 403 0 1 0 0
513758 A 842 283 282 0 1 255 21


Last edited by Don Cragun; 02-13-2015 at 12:06 AM.. Reason: Fix CODE tags.
# 2  
Old 02-13-2015
If you don't mind having the same format in output lines as you have in the input file, and none of fields 6 through 9 ever have negative values, the easy way to do what you requested would be:
Code:
awk '$6 + $7 + $8 + $9' file1 > Output

P.S. If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 02-13-2015
Thanks That worked
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 Column Values in Row

Hi , I have been trying to write a awk script which will have the following Output 1. Append the last Characters of the lines matching pattern xxxxxxxxx & then a space & then Append the last Characters of the lines matching pattern yyyyyyyyy 2. the process will continue till end of file &... (10 Replies)
Discussion started by: newageBATMAN
10 Replies

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

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

9. Shell Programming and Scripting

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 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 ... (3 Replies)
Discussion started by: gotam
3 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