Home Man
Search
Today's Posts
Register

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

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 29  
Old 01-07-2013
Thanks.
I will try and let you know.
# 30  
Old 01-09-2013
Its working
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 02:42 PM..
# 31  
Old 01-09-2013
Quote:
Originally Posted by bioinfo
Its working
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 01: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 01-10-2013
Thanks.
Its working. I modified the way of printing and got the required output.
# 33  
Old 01-10-2013
Quote:
Originally Posted by bioinfo
Thanks.
Its working. I modified the way of printing and got the required output.
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)
# 34  
Old 01-10-2013
I modified the code in printf statement for first output and that helped me in getting second output. yippie

Thanks a lot to you.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Different behavior between bash shell and bash script for cmd da1 Shell Programming and Scripting 5 3 Weeks Ago 06:41 AM
How to run several bash commands put in bash command line? abdulbadii Shell Programming and Scripting 4 01-23-2018 06:11 AM
Bash to select text and apply it to a selected file in bash cmccabe Shell Programming and Scripting 4 09-29-2016 05:36 PM
Im new to bash scriping and i found this expression on a bash script what does this mean. kevin298 UNIX for Dummies Questions & Answers 1 10-26-2012 07:04 PM
Using arrays in bash using strings to bash built-in true kristinu Shell Programming and Scripting 41 03-30-2012 08:07 PM
ARGV and ARGC in bash 3 and bash 3.2 SBC Shell Programming and Scripting 2 06-29-2011 06:53 AM
Bash Script: modify bash LibRid Shell Programming and Scripting 9 10-25-2010 06:17 PM
how to make your bash script run on a machine with csh and bash npatwardhan Shell Programming and Scripting 3 11-19-2008 03:17 AM
bash and ksh: variable lost in loop in bash? estienne Shell Programming and Scripting 2 08-25-2008 02:09 PM
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 12:25 PM


All times are GMT -4. The time now is 06:37 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password