Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Help in awk/bash

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #29  
Old Unix and Linux 01-07-2013   -   Original Discussion by bioinfo
bioinfo's Unix or Linux Image
bioinfo bioinfo is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 12 August 2013, 3:07 AM EDT
Posts: 50
Thanks: 52
Thanked 0 Times in 0 Posts
Thanks. Linux
I will try and let you know.
Sponsored Links
    #30  
Old Unix and Linux 01-09-2013   -   Original Discussion by bioinfo
bioinfo's Unix or Linux Image
bioinfo bioinfo is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 12 August 2013, 3:07 AM EDT
Posts: 50
Thanks: 52
Thanked 0 Times in 0 Posts
Its working Linux

Code:
 printf("The following entry from line %d is for Branch %d:\n%s",
            FNR, entry, r[entry]) > no

But if I want to print the full line as well as branch. Also, I want serial no.
Required output:

Code:
(001) The following entry from entry 5 "print full line here" is for branch 2711:
# Branch 2711 is printed here
(002) The following entry from entry 9 "print full line here" is for branch 2716:
# Branch 2716 is printed here
(003) The following entry from entry 13 "print full line here" is for branch 2916:
# Branch 2916 is printed here

Then, using other file (2.txt having one column of some serial numbers) I wish to retreive those branches from above output corresponding to values from 2.txt. For example, I want to retreive 002 from above output:
Required output:

Code:
(002) The following entry from entry 9 "print full line here" is for branch 2716:
# Branch 2716 is printed here

Please guide.
Thanks

Last edited by bioinfo; 01-09-2013 at 03:42 PM..
Sponsored Links
    #31  
Old Unix and Linux 01-09-2013   -   Original Discussion by bioinfo
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 13 December 2017, 3:56 AM EST
Location: San Jose, CA, USA
Posts: 10,772
Thanks: 590
Thanked 3,771 Times in 3,219 Posts
Quote:
Originally Posted by bioinfo View Post
Its working Linux

Code:
 printf("The following entry from line %d is for Branch %d:\n%s",
            FNR, entry, r[entry]) > no

But if I want to print the full line as well as branch. Also, I want serial no.
Required output:

Code:
(001) The following entry from entry 5 "print full line here" is for branch 2711:
# Branch 2711 is printed here
(002) The following entry from entry 9 "print full line here" is for branch 2716:
# Branch 2716 is printed here
(003) The following entry from entry 13 "print full line here" is for branch 2916:
# Branch 2916 is printed here

Then, using other file (2.txt having one column of some serial numbers) I wish to retreive those branches from above output corresponding to values from 2.txt. For example, I want to retreive 002 from above output:
Required output:

Code:
(002) The following entry from entry 9 "print full line here" is for branch 2716:
# Branch 2716 is printed here

Please guide.
Thanks
With all of the examples I've provided you in both of the active threads you started titled "Help in awk/bash", you should be able to replace the awk printf statement:

Code:
 printf("The following entry from line %d is for Branch %d:\n%s",
            FNR, entry, r[entry]) > no

with one that will produce the output you want.

You know how to create a variable to count the number of lines you've written (e.g., outcnt), you know how to increment that variable before retrieving its value (++outcnt), you know how to use a printf format specifier to print a value as a 3 digit decimal value with leading zero fill (%03d), you know that in awk $0 is the contents of the current line, and you know how to use a printf format specifier to print a variable as a string (%s).

The only thing you might be missing is how to print a double quote character in a printf format string (since you want the full line to be printed between double quote characters). You do that by escaping each double quote you want to print with a backslash character. An example doing that is:
printf("Print a \"%s\" string\n", "quoted")

Please show me that all of the time I've put into providing samples for you is helping you learn how to use awk by trying this one on your own and then showing us what you've done!

Last edited by Don Cragun; 01-10-2013 at 02:11 AM.. Reason: typo
The Following 2 Users Say Thank You to Don Cragun For This Useful Post:
bioinfo (01-10-2013), vgersh99 (01-09-2013)
    #32  
Old Unix and Linux 01-10-2013   -   Original Discussion by bioinfo
bioinfo's Unix or Linux Image
bioinfo bioinfo is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 12 August 2013, 3:07 AM EDT
Posts: 50
Thanks: 52
Thanked 0 Times in 0 Posts
Thanks.
Its working. I modified the way of printing and got the required output. Linux
Sponsored Links
    #33  
Old Unix and Linux 01-10-2013   -   Original Discussion by bioinfo
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 13 December 2017, 3:56 AM EST
Location: San Jose, CA, USA
Posts: 10,772
Thanks: 590
Thanked 3,771 Times in 3,219 Posts
Quote:
Originally Posted by bioinfo View Post
Thanks.
Its working. I modified the way of printing and got the required output. Linux
Great.

Have you figured out how to use awk, sed, or the shell to extract entries listed in 2.txt from the output you just produced?
The Following User Says Thank You to Don Cragun For This Useful Post:
bioinfo (01-10-2013)
Sponsored Links
    #34  
Old Unix and Linux 01-10-2013   -   Original Discussion by bioinfo
bioinfo's Unix or Linux Image
bioinfo bioinfo is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 12 August 2013, 3:07 AM EDT
Posts: 50
Thanks: 52
Thanked 0 Times in 0 Posts
I modified the code in printf statement for first output and that helped me in getting second output. yippie Linux

Thanks a lot to you.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using AWK in a bash script mb001 Shell Programming and Scripting 3 08-02-2011 04:19 PM
awk bash help a-gopal Shell Programming and Scripting 2 05-08-2009 09:39 PM
BASH, HASH and AWK Corpsehy UNIX for Dummies Questions & Answers 2 02-13-2009 02:54 AM
Is there any better way for sorting in bash/awk ahjiefreak Shell Programming and Scripting 7 10-31-2008 10:07 AM
BASH with AWK narasimhulu Shell Programming and Scripting 2 08-26-2008 12:59 AM



All times are GMT -4. The time now is 12:42 PM.