how to append into array thru awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to append into array thru awk
# 1  
Old 09-20-2007
how to append into array thru awk

hey champs,

i have variable as field_dtls,
which has values like
CLIENT ID|FAMILY NAME|MIDDLE NAME|FIRST NAME|COUNTRY NAME|ADDRESS|NATIONAL ID|PASSPORT NUMBER

so,
echo "$field_dtls"
CLIENT ID|FAMILY NAME|MIDDLE NAME|FIRST NAME|COUNTRY NAME|ADDRESS|NATIONAL ID|PASSPORT NUMBER

but i could not fragments these values into arrays based on field separator |

for i in `echo "$field_dtls" | awk -F"|" '{ for (i=1;i<NF;i++) { printf("%s\n",$i)}}'`
> do
> j=1
> var[$j]="$i"
> j=`expr $j + 1`
> done

if i am printing echo ${var[1]}
it showing me o/p as ID

how can i overcome this......e.g echo ${var[1]} should give CLIENT ID
# 2  
Old 09-20-2007
Code:
"`echo "$field_dtls" | awk -F"|" '{ for (i=1;i<NF;i++) { printf("%s\n",$i)}}'`"

# 3  
Old 09-21-2007
thanx a lot.....
i did it in some other way....
awk '{c=split($0, s); for(n=1; n<=c; ++n) print s[n] }' $1
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bash to append array value to file before copying

The bash stores each uniqueid in an array and then passes them to %q to get the unique path. That seems to work what I am having trouble with is renaming each .png with the unique value in %q. I thought it was working but upon closer inspection, a .png file is being sent to scp.... but only 1 and... (21 Replies)
Discussion started by: cmccabe
21 Replies

2. UNIX for Beginners Questions & Answers

Append header with awk

I have to append the header (ie "START OF LINE") to a file only if there is data in it. Below command is showing header though there is no data in a file, can you suggest how to correct.. awk '{NR!=0} BEGIN{print "START OF LINE"}; {print}' file (3 Replies)
Discussion started by: JSKOBS
3 Replies

3. Shell Programming and Scripting

Append awk results into file or array

for a in {1..100} do awk '{ sum+=$a} END {print sum}' a=$a file1 > file2 done I know I will get only one number if following the code above, how can I get 100 sum numbers in file2? (2 Replies)
Discussion started by: wanliushao
2 Replies

4. Shell Programming and Scripting

Awk: Append new elements to an array

Hi all, I'm dealing with a bash script to merge the elements of a set of files and counting how many times each element is present. The last field is the file name. Sample files: head -5 *.tab==> 3J373_P15Ac1y2_01_LS.tab <== chr1 1956362 1956362 G A hom ... (7 Replies)
Discussion started by: lsantome
7 Replies

5. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

6. Shell Programming and Scripting

How to append to array within conditional block in ksh/korn shell?

Hi, I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement. #!/bin/ksh echo "---------------------------------------------------" set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Discussion started by: sanzee007
2 Replies

7. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

8. Shell Programming and Scripting

Python- How to append to an array

Hello, I wrote the following in python that parses mathematical expressions and I'm trying to store the results in an array. For example, if I enter 3+4*2, the array should be . Unfortunately, I get the following: Can anyone help me figure out what is wrong? The tokenizer seems to work... (0 Replies)
Discussion started by: jl487
0 Replies

9. Shell Programming and Scripting

Append using SED/AWK

Hi friends, I have a file with content SOME TEXT HERE I want to append the string GREAT to Line 1 of my file such that the file content should be GREAT SOME TEXT HERE I can do a cat for the string great and file >> newfile and then rename newfile name to file But this does not put... (5 Replies)
Discussion started by: dahlia84
5 Replies

10. Shell Programming and Scripting

Append using awk

Hi All, I have a problem with my awk script. I am trying to append the whole line to another file called " file.txt " but i can't. I suppose there's something wrong in the way that i pipe. I canot use " nawk -f awk_script input > file.txt " because i have a 2nd input. Can any expert give some... (4 Replies)
Discussion started by: Raynon
4 Replies
Login or Register to Ask a Question