# Array Help

**URL:** <https://community.unix.com/t/array-help/328499>\
**Category:** Shell Programming and Scripting\
**Created:** [May 14, 2013, 3:44am UTC](https://community.unix.com/t/array-help/328499 "2013-05-14T03:44:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ragu.selvaraj](https://community.unix.com/letter_avatar/ragu.selvaraj/32/6_22734026db12803ebb3e059622ac3534.png) [@ragu.selvaraj](https://community.unix.com/u/ragu.selvaraj)\
**Post date:** [May 14, 2013, 3:44am UTC](https://community.unix.com/t/array-help/328499/1 "2013-05-14T03:44:03Z")

</div>

Hi

Am having 2 files

1st file having

1 2 3 4 5 6 7 8 9

2nd file  
1  
2  
b  
3  
c

i want to check eache character in 2nd file is present or not  
need to check whether 1 is present in 1st file

rec=`cat 2nd file`  
for i in $rec  
if [ $i = 1st file (how to check using array concept?

---

<div class="post-metadata">

**Author:** ![vidyadhar85](https://community.unix.com/user_avatar/community.unix.com/vidyadhar85/32/997_2.png) [@vidyadhar85](https://community.unix.com/u/vidyadhar85)\
**Post date:** [May 14, 2013, 3:58am UTC](https://community.unix.com/t/array-help/328499/2 "2013-05-14T03:58:22Z")

</div>

So your 1st file has only 1 row? if yes..

```nohighlight
 
awk 'NR==FNR{v=$0;next}
v ~ $0{print $0"exists in 1st file"}' 1stfile 2ndfile

```

---

<div class="post-metadata">

**Author:** ![ragu.selvaraj](https://community.unix.com/letter_avatar/ragu.selvaraj/32/6_22734026db12803ebb3e059622ac3534.png) [@ragu.selvaraj](https://community.unix.com/u/ragu.selvaraj)\
**Post date:** [May 14, 2013, 4:01am UTC](https://community.unix.com/t/array-help/328499/3 "2013-05-14T04:01:02Z")

</div>

i want to print he character which is not present in the 1st file

---

<div class="post-metadata">

**Author:** ![vidyadhar85](https://community.unix.com/user_avatar/community.unix.com/vidyadhar85/32/997_2.png) [@vidyadhar85](https://community.unix.com/u/vidyadhar85)\
**Post date:** [May 14, 2013, 4:04am UTC](https://community.unix.com/t/array-help/328499/4 "2013-05-14T04:04:58Z")

</div>

change it as below..

```nohighlight
 
awk 'NR==FNR{v=$0;next}
v !~ $0{print $0"exists in 1st file"}' 1stfile 2ndfile

```

---

<div class="post-metadata">

**Author:** ![Jotne](https://community.unix.com/user_avatar/community.unix.com/jotne/32/2148_2.png) [@Jotne](https://community.unix.com/u/Jotne)\
**Post date:** [May 14, 2013, 4:09am UTC](https://community.unix.com/t/array-help/328499/5 "2013-05-14T04:09:40Z")

</div>

A small correction 🙂

```nohighlight
awk 'NR==FNR{v=$0;next}
v !~ $0{print $0,"exists not in 1st file"}' 1stfile 2ndfile

```

```nohighlight
b exists not in 1st file
c exists not in 1st file

```

---

<div class="post-metadata">

**Author:** ![ragu.selvaraj](https://community.unix.com/letter_avatar/ragu.selvaraj/32/6_22734026db12803ebb3e059622ac3534.png) [@ragu.selvaraj](https://community.unix.com/u/ragu.selvaraj)\
**Post date:** [May 14, 2013, 6:55am UTC](https://community.unix.com/t/array-help/328499/6 "2013-05-14T06:55:48Z")

</div>

hi jote

thank you

i want to execute in loop i need the condition like

if a in (2nd file a b c d.....)

then  
echo string is correct  
else echo string in not in 2nd file

fi

---

<div class="post-metadata">

**Author:** ![vidyadhar85](https://community.unix.com/user_avatar/community.unix.com/vidyadhar85/32/997_2.png) [@vidyadhar85](https://community.unix.com/u/vidyadhar85)\
**Post date:** [May 14, 2013, 6:58am UTC](https://community.unix.com/t/array-help/328499/7 "2013-05-14T06:58:20Z")

</div>

Is there any specific reason for loop? I guess awk fits the purpose (as per your details). Are we missing anything here?

---

<div class="post-metadata">

**Author:** ![ragu.selvaraj](https://community.unix.com/letter_avatar/ragu.selvaraj/32/6_22734026db12803ebb3e059622ac3534.png) [@ragu.selvaraj](https://community.unix.com/u/ragu.selvaraj)\
**Post date:** [May 14, 2013, 7:33am UTC](https://community.unix.com/t/array-help/328499/8 "2013-05-14T07:33:10Z")

</div>

yes

am writing a script to identify whether the string is present or not

for example

consider a record  
abcd,1234,xyz

i need to validate whether the first column delimeter as , abc

is present in the array (a b c d e f)

if it is present then no issue else i need to print tha string

---------- Post updated at 06:33 AM ---------- Previous update was at 06:05 AM ----------

yes

i need to find the character which is nt present there will be many records

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/6_22734026db12803ebb3e059622ac3534.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [May 14, 2013, 12:39pm UTC](https://community.unix.com/t/array-help/328499/9 "2013-05-14T12:39:19Z")

</div>

The delimiter , will never be present in the array (a b c d e f). I'm not sure what you were expecting.
