awk script to call another script based on second column entry

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk script to call another script based on second column entry
# 1  
Old 02-08-2016
awk script to call another script based on second column entry


I have a text file (Input.txt) with two column entries separated by tab as given below:

aaa  str1
bbb  str2
cccccc  str3
dddd  str4
eee  str3
ssss  str2
sdf  str3
hhh  str1
fff  str2
ccc  str3

My problem is, I want to write an awk script (say FirstScript) which will call another script (say SecondScript)which will return a string if a match of "str3" is found in the second column. After matching, the string returned by the second script will be written in the third column separated by a tab. If no match is found, the string from the first column will be copied to the corresponding row in the third column.

The desired output OUTPUT.TXT :

aaa  str1  aaa
bbb  str2  bbb
cccccc  str3   xxx
dddd  str4  dddd
eee  str3  yyy
ssss  str2  ssss
sdf  str3  zzz
hhh  str1  hhh
fff  str2  fff
ccc  str3   xyz

In the output file, OUTPUT.TXT

cccccc str3 xxx
eee str3 yyy
sdf str3 zzz
ccc str3 xyz

Here the input to the SecondScript are cccccc, eee, sdf and ccc respectively for each row. xxx, yyy, zzz and xyz are returned by the SecondScript.

Please help me.

Thanks in advance.Smilie

Last edited by my_Perl; 02-08-2016 at 12:45 PM.. Reason: Editing
# 2  
Old 02-08-2016
Please use code tags as required by forum rules!

Any attempts/ideas/thoughts from your side? Your strategy is not too clear. Why the "two script" approach? Why a .sh (shell) script to be called from within awk? How should the desired output look like?
This User Gave Thanks to RudiC For This Post:
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/sed summation of one column based on some entry in first column

Hi All , I am having an input file as stated below Input file 6 ddk/djhdj/djhdj/Q 10 0.5 dhd/jdjd.djd.nd/QB 01 0.5 hdhd/jd/jd/jdj/Q 10 0.5 512 hd/hdh/gdh/Q 01 0.5 jdjd/jd/ud/j/QB 10 0.5 HD/jsj/djd/Q 01 0.5 71 hdh/jjd/dj/jd/Q 10 0.5 ... (5 Replies)
Discussion started by: kshitij
5 Replies

2. UNIX for Beginners Questions & Answers

Shell script to call and sort awk script and output

I'm trying to create a shell script that takes a awk script that I wrote and a filename as an argument. I was able to get that done but I'm having trouble figuring out how to keep the header of the output at the top but sort the rest of the rows alphabetically. This is what I have now but it is... (1 Reply)
Discussion started by: Eric7giants
1 Replies

3. Shell Programming and Scripting

Sum of a column as new column based on header in a script

Hello, I am trying to store sum of a column as a new column inside a file but have to find the column names dynamically I/p c1,c2,c3,c4,c5 10,20,30,40,50 20,30,40,50,60 If i want to find sum only column c1, c3 and output it as c6,c7 O/p c1,c2,c3,c4,c5,c6,c7 10,20,30,40,50,30,70... (6 Replies)
Discussion started by: mkathi
6 Replies

4. Shell Programming and Scripting

Call script parameter based on dates

Hi Guys, I am having a script which needs to be iterated based on date passed and itrate based on no of months given. #!/bin/bash var_d=$1 months=$2 sh invoke_script var_d i need to iterate the inside script something like below sh invoke_script 170101 sh invoke_script... (4 Replies)
Discussion started by: Master_Mind
4 Replies

5. Shell Programming and Scripting

Call awk script

The below awk script (loop.awk) is in the cygwin home directory. I do a cd to the directory where the Sources.txt is (where I would like the data output in), but the script does not run: echo loop | ./loop.awk loop.awk #!/bin/awk -f BEGIN {} cat Sources.txt | while read a do... (10 Replies)
Discussion started by: cmccabe
10 Replies

6. AIX

Commands to call script work from command line but not from Cron entry

My first post evidently did not materialize so I posted it again: Runnning a cron job every 5 mins to send data files to a state facility. My original cron entry at worked fine: 01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh Somewhere I have a... (1 Reply)
Discussion started by: Skyybugg
1 Replies

7. Shell Programming and Scripting

awk based script to print the "mode(statistics term)" for each column in a data file

Hi All, Thanks all for the continued support so far. Today, I need to find the most occurring string/number(also called mode in statistics terminology) for each column in a data file (.csv type). For one column of data(1.txt) like below Sample 1 2 2 3 4 1 1 1 2 I can find the mode... (6 Replies)
Discussion started by: ks_reddy
6 Replies

8. Shell Programming and Scripting

Call shell script function from awk script

hi everyone i am trying to do this bash> cat deepak() { echo Deepak } deepak bash>./ Deepak so it is giving me write simply i created a func and it worked now i modified it like this way bash> cat (2 Replies)
Discussion started by: aishsimplesweet
2 Replies

9. Shell Programming and Scripting

for each different entry in column 1 extract maximum values from column 2 in unix/awk

Hello, I have 2 columns (1st column has multiple entries but the corresponding values in the column 2 may be the same or different.) however I want to extract unique values for each entry in column 1 by assigning the max value from column 2 SDF4 -0.211654 SDF4 0.978068 ... (1 Reply)
Discussion started by: Diya123
1 Replies

10. Shell Programming and Scripting

How to call parametrs to awk script

Hi All, I have script to handle nulls in column2 from file1.txt and redirect its output to file2.txt I am confused with run-time command line arguments. b'cause i normal unix we use $1 $2 for two parameters. But in awk it treat $1 as column1. So, i tried with awk -v var1 -v var2... how to... (7 Replies)
Discussion started by: kmsekhar
7 Replies
Login or Register to Ask a Question

Featured Tech Videos