awk Format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk Format
# 1  
Old 01-05-2014
awk Format

Guys ,, pls .. need help with this ...

File 1
Code:
 
0A6C Not Visible            ???:?  NA:NA  TDEV          N/Grp'd      NR    5121
0A6D Not Visible            ***:*  NA:NA  TDEV          N/Grp'd      RW   33784
0A6E Not Visible            ***:*  NA:NA  TDEV          N/Grp'd      RW   33784
0A6F Not Visible            ***:*  NA:NA  TDEV          N/Grp'd      RW   33784
0A6F Not Visible            ***:*  NA:NA  TDEV          N/Grp'd      RW   33784
0A70 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd      RW   34816
0A71 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (M) RW  214988
0A72 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A73 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A74 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A75 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A76 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A79 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (M) RW  180180
0A7A Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A7B Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A7C Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A7D Not Visible            ***:*  NA:NA  TDEV          N/Grp'd      RW   46080

File 2
Code:
0A6F
0A70
0A71
0A79

Output needed
Code:
 
0A6F
0A70
0A71
0A72
0A73
0A74
0A75
0A76
0A79
0A7A
0A7B
0A7C

Basically get the column 1 from file 2 where column 1(file2) = column 1(file1)
Also if $8 = (M) for the matched value , also get all the column 1 entries ( file2) with the below logic
from (M) to the next (M) or till $8 is not (m) or (M) get all $1 entries

Thanks
# 2  
Old 01-05-2014
You have asked for our help writing awk scripts 40 times over the last five and a half years. It seems that the logic needed to solve this problem overlaps with some of your earlier requests. What have you tried so far?

What values (other than an empty string, (m), and (M)) can appear in the 8th column in your input file? Can the 9th column in your input file ever be an empty string, (m), or (M)? If the 9th column can be an empty string, can the 10th column ever contain (m) or (M)?
# 3  
Old 01-06-2014
I was able to get the result by doing a for loop ..and executing this for each line in file2 .. for example ....

Code:
 
cat /tmp/file1| nawk '{if($8=="(M)" || $8=="(m)") print $1,$8,$10}' |nawk '/(M)/{$0="\n"$0}1'|sed -e "/./{H;$!d;}" -e "x;/0A71 /!d;/-/!d" |awk '{print $1}' 
 
which would result in 
0A71
0A72
0A73
0A74
0A75
0A76

I was looking for easier option ... something like a one liner ....
If $8 is (M) ... get all the column1's till the $NF = "-"

Thanks
# 4  
Old 01-06-2014
Hi, with your given sample something like this might work:

Code:
awk 'NR==FNR{A[$1]; next} $1 in A || $8=="(m)" || $8=="(M)"{delete A[$1]; print $1}' file2 file1

or perhaps also:
Code:
awk 'NR==FNR{A[$1]; next} $1 in A || NF==10 {delete A[$1]; print $1}' file2 file1

But maybe not with your actual file. Is it TAB-separated or fixed position ?
# 5  
Old 01-06-2014
Thx ...but its not working ....for example when looking for 0A71 in file 2 , $8 is (M)
so i need $1 from following

Code:
0A71 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (M) RW  214988
0A72 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A73 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A74 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A75 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -
0A76 Not Visible            ***:*  NA:NA  RDF1+TDEV     N/Grp'd  (m) RW       -

If $8 = (M) , print $1 till $NF !~ "-"

Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk incorrect format

I was wondering whether anyone has any idea what is happening here. I'm using simple code to compare 2 tab delimited files based on column 1 values. If the column1 value of file1 exists in file2, then I'm to print the column4 value in file2 in column3 of file1. Here is my code: 1st I have to... (6 Replies)
Discussion started by: Geneanalyst
6 Replies

2. Shell Programming and Scripting

Format a file using awk

I have a file as below empty May7 noread May8 How can process this file and print as below. neat and clean. Filename Date Created empty May7 noread May8 I tried something with printf before creating the file itself... (3 Replies)
Discussion started by: Tuxidow
3 Replies

3. UNIX for Dummies Questions & Answers

Solaris8 = How to format this df -k | awk

Hi, Unfortunately, we still have Solaris 8 to support and it does not support df -h so I am stucked with having to use df -k. UNIX shell is ksh. Example of df -k run is below: $ df -k /db/test01 | awk '{ print }' Filesystem kbytes used avail capacity Mounted on... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. Shell Programming and Scripting

Format using AWK

Need some help .. in formating some input INPUT FILE IMAGE ap00m43 0 0 8 ap00m43_1318914034 UNIX_STANDARD_ADC_2 0 *NULL* root Daily 1 0 1318914034 408 1319518834 0 HISTO -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 FRAG 1 1 0 0 2 20 6 G11890 ts00p71 65536 FRAG 1 2 13440 0 2 20 7 G11890 ts00p71... (2 Replies)
Discussion started by: greycells
2 Replies

5. Shell Programming and Scripting

Format in AWK please

Am new to AWk, Can anyone help me to get excepected output from given input please. input file student: name details of them = details_needed class: 5th_needed adress: address_needed Expected output: details of them = 5th_needed = address_needed ---------- Post updated at... (5 Replies)
Discussion started by: Elavarasan
5 Replies

6. Shell Programming and Scripting

awk:How to format a number?

Hello, I need to format a number..like 12900 should be printed as 12,900 and 1209 as 1,209 and so on. (Just like we do in excel). Can this be done in awk. any printf options we have?Please suggest me. Thanks! (8 Replies)
Discussion started by: vijay_0209
8 Replies

7. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

8. Shell Programming and Scripting

How to format columns using AWK

Hi, How to format something like this: John Roberts 324-141-984 Acct Jack Williams 159-555-555 Acct William Jackson 949-911-888 Acct Mark J Walton 145-852-252 Acct Fred P Milton 483-244-390 Acct Bill P J Miller 404-050-223 Acct into... (12 Replies)
Discussion started by: ora_umair
12 Replies

9. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

10. Shell Programming and Scripting

data format from (4.56 0.7) -> 4.6(7) awk?!

Hi, I have to manipulate a data file which say reads like this {$index $value $error_on_value} aa 4.56 0.7 bb 123.456 0.00987 cc 987654 321 . . in easily human readable format of type aa 4.6(7) bb 123.456(1) cc 9.877(3)e+05 value rounded to 4.6 with error of 0.7 on the last... (4 Replies)
Discussion started by: ahan
4 Replies
Login or Register to Ask a Question