Help with awk: printing variables

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk: printing variables
# 1  
Old 06-16-2011
Help with awk: printing variables

awk is only printing out the variables on the first AK2, how do I get it to print out the variables for every occurrence of AK2?

grep -l "^ST.997" *.replaced|sort -n|uniq>FILELIST
while read file
let "count = $count+1"
<$file awk 'BEGIN {
/^ISA/  { ISA06SEND=$7
              ISA14CTRL=$13     }
/^GS/   { GS01GSTYP=$2
               GS06CNTL=$7       }
/^AK1/  { AK101GSTYP=$2
              AK102GSCTRL=$3   }
/^AK3/  { AK301SEG=$2
              AK304SEGERR=$5   }
/^AK4/  { AK401ELPOS=$2
              AK404ERRDATA=$5 }
/^AK5/  { AK501STACK=$2
              AK502STERRCD=$3 }
/^AK9/  { AK901GSACK=$2
              AK905GSERRCD=$6 }     
/^AK2/  { AK201STTYP=$2
echo "FA_FILE $count:  Working with $file"

INPUT looks like this:
ISA~00~          ~00~          ~ZZ~RRRR           ~ZZ~FFF FIAC       ~110611~2215~U~00301~000002391~0~P~>
GS~FA~RRRR MFG~FFFXMFG~110611~2215~1847~X~002000
AK2~830~000031588 #I want to print the other variables for every occurrence of AK2
OUTPUT should look this:
RRRR           ,FFF FIAC       ,000002391,FA,RRRR MFG,1847,PO,970,830,000031588,,,,,,A,,A,186,186,186,,
RRRR           ,FFF FIAC       ,000002391,FA,RRRR MFG,1847,PO,970,830,000031589,,,,,,A,,A,186,186,186,,
RRRR           ,FFF FIAC       ,000002391,FA,RRRR MFG,1847,PO,970,830,000031590,,,,,,A,,A,186,186,186,,

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Echo not printing the variables with delimiters as required

This is the file which contains only neccessary values from the output of curl command i.e TEMP_FILE Proxy Hostname Proxy IP address XXX.XXX.XX.XX port 0000 Proxy Version SGOS X.X.X.X Proxy Serial # ... (5 Replies)
Discussion started by: ramprabhum
5 Replies

2. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

3. Shell Programming and Scripting

awk - Why can't value of awk variables be passed to external functions ?

I wrote a very simple script to understand how to call user-defined functions from within awk after reading this post. function my_func_local { echo "In func $1" } export -f my_func_local echo $1 | awk -F"/" '{for (k=1;k<=NF;k++) { if ($k == "a" ) { system("my_local_func $k") } else{... (19 Replies)
Discussion started by: sreyan32
19 Replies

4. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

5. Shell Programming and Scripting

awk question for printing variables

Hi All, I have the following awk code where I am passing 4 variables to the program and I need to print them in the awk script. The variables are $start_month $start_date - $end_month $end_date. printf("\tFor More Information\n") > out_tmp1 printf("\tIf you have any questions about this... (6 Replies)
Discussion started by: nua7
6 Replies

6. Shell Programming and Scripting

Printing using awk

Hi I am relatively new to awk so i am getting confused a lot I am in need of help ... I am trying to append coloumns to the end of line using AWK I tried using this command awk -F "," '{for(s=7;s<=217;s++);$s="0";}1' OFS=, sam_sri_out It is giving me an output like this...... (1 Reply)
Discussion started by: Sri3001
1 Replies

7. Shell Programming and Scripting

Awk variables not printing to StdOutput

Hi guys, I'd be grateful if you could have a look at my code below and give me some feedback as to why the homedir and fullname variables aren't being printed to Standard Output when the script is run. Many thanks. read -p "Please type in username you wish to get information from: " username ... (6 Replies)
Discussion started by: jjb1989
6 Replies

8. Shell Programming and Scripting

AWK printing

i have a file containing a line 123456 is it possible to use AWK to print it out to look like 1 2 3 4 5 6 (8 Replies)
Discussion started by: tomjones
8 Replies

9. Shell Programming and Scripting

AWK Printing

i have a file and i want to print the second variable and add qoutes to it i do awk -F"|" '{print $2}' star.unl. i get the output xxxxxxx but i need the variable($2) to be in "xxxxxxx" how do i do there please (3 Replies)
Discussion started by: tomjones
3 Replies

10. Shell Programming and Scripting

AWK printing

Hello, I am trying to write a formatted report into a file using .ksh script and awk. Here is the command I am trying to run echo "before awk" ${SRC_SCHEMA} echo | awk '{printf "%-20s", ${SRC_SCHEMA} }' >>$REPORT_SQL_NAME I get the following error before awk ADW awk: 0602-562 Field $()... (1 Reply)
Discussion started by: fastgoon
1 Replies
Login or Register to Ask a Question