awk to add tab to output of both conditions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to add tab to output of both conditions
# 1  
Old 10-21-2016
awk to add tab to output of both conditions

In the below awk written by @RavinderSingh13 I have added a few lines and am trying to have the output be tab-delimited. The input is space-delimeted and the portion in bold seems to add a tab to the Not found but not the found. Thank you Smilie.

file1
Code:
One 1
Two 2
Three 3

file2
Code:
One 1
Two 5
Three 3

awk
Code:
awk 'FNR==NR{
 A[$2]=$2;
 next
 }
 {
 for(i in A){
 if($2>=i+0 && $2<=A[i]+0){
 $0=$0 " found";
 print;
 next
 }
 };
 printf("%s\t%s\n",$0,($1 ~ /Match/ || $1 ~ /Missing/)?"":" Not found")
 }
 ' file1 file2 > output

Current output
Code:
One 1 found
Two 5     Not found     --- tab-delimited 
Three 3 found

Current output --- all tab-delimited
Code:
One 1     found
Two 5     Not found
Three 3     found

# 2  
Old 10-21-2016
Hello cmccabe,

Could you please change $0=$0 " found";to$0=$0 "\tfound"; and let me know if this helps you.

Thanks,
R. Singh

Last edited by RavinderSingh13; 10-21-2016 at 06:13 PM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 10-21-2016
Thank you, works great Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk printing leading tab in output

The awk below executes and produces the current output. it skips the header in row 1 and prints $4,$5,$6 and then adds the header row back. The problem is that it keeps the tailing tab and prints it in front of $1. I could add a pipe to remove the tab, but is there a better way to do it with on... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

awk to add lines with symbol to output file

In the awk below which does execute I get output that is close, except for all the lines that start with a # are removed. Some lines have one others two or three and after the script adds the ID= to the fields below the pattern in the awk, I can not seem to add the # lines back to the output. ... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

awk output is space delimeted not tab delimeted

In the below awk the output is space delimited, but it should be tab delimited. Did I not add the correct -F and OFS? Thank you :). The input file are rather large so I did not include them, but they are tab-delimeted files as well. awk awk -F'\t' -v OFS='\t' 'FNR==1 { next } > ... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

awk output seperated by tab

I am just trying to output the below awk separated by tabs. Thank you :). awk (added OFS as an attempt to itroduce tabs) awk '{split($5,a,"-"); OFS='\t' print $1,$2,$3,a}' file.bed > test.bed The awk runs and produces all the data in 1 field instead of 4 fields. current output ... (2 Replies)
Discussion started by: cmccabe
2 Replies

5. Shell Programming and Scripting

Gawk output separated by tab

In the gawk below, I am trying to output the file tab-deliminated but don't think that is the correct syntax. Thank you :). gawk OFS='/t' '{sub(/-+/,"",$2); ar=$0} END{n = asort(ar) for (i = 1; i <= n; i++) print ar}' file (2 Replies)
Discussion started by: cmccabe
2 Replies

6. Shell Programming and Scripting

awk problems - awk ignores conditions

awk 'BEGIN{ if('"$CATE"'<'"${WARN}"') printf ("%s", "'"`Kfunc "" ; break`"'") else if (('"${CATE}"'>='"${WARN}"') && ('"${CATE}"'<'"${CRIT}"')) printf ("%s", "'"`Wfunc ""; break`"'") else if ('"${CATE}"'>='"${CRIT}"') printf... (6 Replies)
Discussion started by: SkySmart
6 Replies

7. Shell Programming and Scripting

If conditions in awk

Hello Friends, I need to find some CDRs in production servers whose 1st field value and 2nd field value = 1 and 11th looks like 45.123... where there are more than 3 digits after comma.so i wrote a one liner, something like below but does not work, however when i used first and second conditions... (8 Replies)
Discussion started by: EAGL€
8 Replies

8. Shell Programming and Scripting

awk three conditions

I'm having a problem pulling UID's from data. The data outputs a user's UID in one of three ways: 1. Error User user_name already assigned with <UID> 2. Success <UID> reserved for user_name 3. <a load of crap because there was a db failure yet somehow the UID is still in there> I typically... (5 Replies)
Discussion started by: MaindotC
5 Replies

9. UNIX for Dummies Questions & Answers

AWK: add and sum line in output

Hi, I have this output: extended device statistics device r/s w/s kr/s kw/s wait actv svc_t %w %b sd1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 sd2 0.1 2.9 2.6 24.8 0.0 0.1 21.0 0 1 sd3 0.1 2.9 2.7 24.8 0.0 ... (9 Replies)
Discussion started by: mjnman
9 Replies

10. Shell Programming and Scripting

output - tab formatted - awk

Dear All, Good Day. I would like to hear your suggestions for the following problem: I have a file with 5 columns with some numbers in 16 lines as shown below. Input file: Col 1 Col 2 Col 3 Col 4 Col 5 12 220 2 121 20 234 30 22 9... (3 Replies)
Discussion started by: Fredrick
3 Replies
Login or Register to Ask a Question