# extract the data using AWK command

**URL:** <https://community.unix.com/t/extract-the-data-using-awk-command/312224>\
**Category:** Shell Programming and Scripting\
**Created:** [June 20, 2012, 10:09am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224 "2012-06-20T10:09:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![katakamvivek](https://community.unix.com/letter_avatar/katakamvivek/32/5_5575768a8748004e209b776fc1b2916d.png) [@katakamvivek](https://community.unix.com/u/katakamvivek)\
**Post date:** [June 20, 2012, 10:09am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/1 "2012-06-20T10:09:23Z")

</div>

In a file i have a data like  
INPUT:

```nohighlight
no,name,company
1,vivek,hcl
2,senthil,cts
1,narsi,hcl
4,prabhakaran,ibm

```

OUTPUT:

```nohighlight
1,vivek,hcl
1,narsi,hcl

```

Using AWK command i want to display the names those having no:1 and company:hcl.Please tell me the command to display above result.

---

<div class="post-metadata">

**Author:** ![elixir\_sinari](https://community.unix.com/user_avatar/community.unix.com/elixir_sinari/32/2563_2.png) [@elixir\_sinari](https://community.unix.com/u/elixir_sinari)\
**Post date:** [June 20, 2012, 10:14am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/2 "2012-06-20T10:14:19Z")

</div>

```nohighlight
awk -F, '$1==1 && $3=="hcl"' inputfile

```

---

<div class="post-metadata">

**Author:** ![katakamvivek](https://community.unix.com/letter_avatar/katakamvivek/32/5_5575768a8748004e209b776fc1b2916d.png) [@katakamvivek](https://community.unix.com/u/katakamvivek)\
**Post date:** [June 20, 2012, 10:20am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/3 "2012-06-20T10:20:03Z")

</div>

thanks,please tell the command if i want to delete the line which has $1=1 and $3="hcl"

---

<div class="post-metadata">

**Author:** ![complex.invoke](https://community.unix.com/user_avatar/community.unix.com/complex.invoke/32/2699_2.png) [@complex.invoke](https://community.unix.com/u/complex.invoke)\
**Post date:** [June 20, 2012, 10:27am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/4 "2012-06-20T10:27:48Z")

</div>

```nohighlight
sed -n '/1,\(.*\),hcl/!p' infile

```

or

```nohighlight
sed '/1,\(.*\),hcl/d' infile

```

---

<div class="post-metadata">

**Author:** ![katakamvivek](https://community.unix.com/letter_avatar/katakamvivek/32/5_5575768a8748004e209b776fc1b2916d.png) [@katakamvivek](https://community.unix.com/u/katakamvivek)\
**Post date:** [June 20, 2012, 10:31am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/5 "2012-06-20T10:31:12Z")

</div>

cant we achive this using AWK command?

---

<div class="post-metadata">

**Author:** ![ctsgnb](https://community.unix.com/letter_avatar/ctsgnb/32/5_5575768a8748004e209b776fc1b2916d.png) [@ctsgnb](https://community.unix.com/u/ctsgnb)\
**Post date:** [June 20, 2012, 10:33am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/6 "2012-06-20T10:33:40Z")

</div>

```nohighlight
awk -F, '$1==1 && $3=="hcl"{next}1' inputfile

```

---

<div class="post-metadata">

**Author:** ![complex.invoke](https://community.unix.com/user_avatar/community.unix.com/complex.invoke/32/2699_2.png) [@complex.invoke](https://community.unix.com/u/complex.invoke)\
**Post date:** [June 20, 2012, 10:34am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/7 "2012-06-20T10:34:11Z")

</div>

ctsgnb posted

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [June 20, 2012, 10:34am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/8 "2012-06-20T10:34:37Z")

</div>

> [@katakamvivek](#):
>
> thanks,please tell the command if i want to delete the line which has $1=1 and $3="hcl"

Simply reverse the logic with !( ... )

---

<div class="post-metadata">

**Author:** ![katakamvivek](https://community.unix.com/letter_avatar/katakamvivek/32/5_5575768a8748004e209b776fc1b2916d.png) [@katakamvivek](https://community.unix.com/u/katakamvivek)\
**Post date:** [June 20, 2012, 10:44am UTC](https://community.unix.com/t/extract-the-data-using-awk-command/312224/9 "2012-06-20T10:44:29Z")

</div>

Its working fine,Thanks.
