awk if condition match and print all


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk if condition match and print all
# 8  
Old 02-08-2015
Try:
Code:
sbin7=2
awk -v n=300 -v corr="$sbin7" '$1==n{$2-=corr} {printf "%9d %5d %7.2f\n",$1,$2,$3}' file

Note that this adaptation is needed because file your format is different from the sample in post #1.
This is why it is important to make your sample representative for the real data right from the start.
This User Gave Thanks to Scrutinizer For This Post:
# 9  
Old 02-09-2015
Thanks all. Next time i will put the real copy of sample file(format) so that thing can be solved at one shot Smilie
It is working now.
# 10  
Old 03-18-2015
working fine, but has complaint about the decimal point which is too long.
See the sample :
before:
Code:
Sort Total
      Site    Sort  SortName   Parts   %/Total
----------------------------------------------
               9                1    0.06
              10               6    0.35

Using command :
Code:
awk '$1 ==    10 {$2-=1;$3=$2/1720*100} 1' filename|sed 's/^10 /               10               /g'

result:
Code:
Sort Total
      Site    Sort  SortName   Parts   %/Total
----------------------------------------------
               9                1    0.06
              10               5 0.290698

The thing is, I need the 0.290698 above to just have 2 decimal point, become --> 0.29
So I need advice ! Thkxxx !

Desire result:
Code:
Sort Total
      Site    Sort  SortName   Parts   %/Total
----------------------------------------------
               9                1    0.06
              10               5    0.29

# 11  
Old 03-18-2015
Moderator's Comments:
Mod Comment 1st we have a requirement to look for the value 300 and perform some calculations. Then the data format changes. Then the output format changes and additional calculations are needed. Now, after more than a month, the input and output format and calculations change again. And, the way to format the output as requested was given more than a month ago.

When you have a new problem open a new thread.

Try to apply suggestions you have been given before asking the same question again.

This thread is closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. UNIX for Beginners Questions & Answers

awk - print when condition is met

I have a file.txt containing the following: Query= HWI-ST863:386:C5Y8UACXX:3:2302:16454:89688 1:N:0:ACACGAAT Length=100 Score E Sequences producing significant alignments: (Bits) Value ... (2 Replies)
Discussion started by: tons92
2 Replies

3. Shell Programming and Scripting

awk Match and Print

I have the following script in place that will print the values of FileB when the first column matches File A's first column. awk 'NR == FNR {A=$2;next};$1 in A {print $1,$NF,$2,$3,A}' FileA FileB Input FileA 3013 4 FileB 3013 2009 03 JUNK 43 Output 3013 43 2009 03 (2 Replies)
Discussion started by: ncwxpanther
2 Replies

4. Shell Programming and Scripting

Using awk for match and print

I have the need to match up the lat / lon from a fileA with the lat / lon and value from fileB. fileA is a small subset of fileB I have the following awk script but it prints out all the contents from fileB. I only need the matches. awk 'FNR==NR {A=$NF; next} {A=$NF} END{for(i in A) printf... (10 Replies)
Discussion started by: ncwxpanther
10 Replies

5. Shell Programming and Scripting

awk if condition match and fix print decimal place

Hi All, I have problem in the middle of implementing to users, whereby the complaint is all about the decimal place which is too long. I need two decimal places only, but the outcome from command is always fixed to 6. See the sample : before: Sort Total Site Sort SortName Parts ... (3 Replies)
Discussion started by: horsepower
3 Replies

6. Shell Programming and Scripting

awk question: How to print condition of NR & NF together.

Experts: LINE1 :This is line one The FIRST line of the file. LINE2 :This is line two LINE3 :This is line three with 8 fileds LINE4 :This is line four LINE5 :This is line five LINE6 :This is line six with 8 fileds I want to delete line 1, and then process the file and want to print lines... (2 Replies)
Discussion started by: rveri
2 Replies

7. Shell Programming and Scripting

[AWK script]Counting the character in record and print them in condition

.......... (1 Reply)
Discussion started by: Antonlee
1 Replies

8. Shell Programming and Scripting

AWK match and print

I have thousands of tables compiled in a single txt document that I'm parsing with AWK. Scattered throughout the document in random sections I would like to parse out the sections that look like this: 1 Seq. Descrição do bem Tipo do bem Valor do bem (R$) 2 1 LOCALIZADO ANA RUA PESSEGO N 96... (3 Replies)
Discussion started by: daveyabe
3 Replies

9. Shell Programming and Scripting

awk to print lines based on string match on another line and condition

Hi folks, I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Discussion started by: rowie718
5 Replies

10. Shell Programming and Scripting

Awk to print on condition in input file

I need only those records which has $2 equal to "DEF" independent of case (i.e upper or lower) nawk -F"," '$2 ~ //{print $0}' file This returns 3rd record also which i dont want I tried this but this doesnt work as expected. nawk -F"," '$2 == ""{print $0}' file i dont... (3 Replies)
Discussion started by: pinnacle
3 Replies
Login or Register to Ask a Question