# Parsing text file

**URL:** <https://community.unix.com/t/parsing-text-file/315212>\
**Category:** Shell Programming and Scripting\
**Created:** [August 15, 2012, 3:44pm UTC](https://community.unix.com/t/parsing-text-file/315212 "2012-08-15T15:44:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobs.smith](https://community.unix.com/letter_avatar/jacobs.smith/32/5_5575768a8748004e209b776fc1b2916d.png) [@jacobs.smith](https://community.unix.com/u/jacobs.smith)\
**Post date:** [August 15, 2012, 3:44pm UTC](https://community.unix.com/t/parsing-text-file/315212/1 "2012-08-15T15:44:06Z")

</div>

Hi Friends,

I am back for the second round today - 😃

My input text file is this way

```nohighlight
Home
friends
friendship meter
Tools
Mirrors
Downloads
My Data
About Us
Help
My own results
 	
BLAT Search Results

   ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND START END SPAN
---------------------------------------------------------------------------------------------------
browser details unix.comwild 20 77 96 100 100.0% 1 + 1234567 1234568 20
browser details help.comwild 20 77 96 100 100.0% 1 + 1234567 1234569 20
browser details milk.comwild 20 77 96 100 100.0% 1 + 1234568 1234569 20
Home
friends
friendship meter
Tools
Mirrors
Downloads
My Data
About Us
Help
My own results
 	
BLAT Search Results

   ACTIONS QUERY SCORE START END QSIZE IDENTITY CHRO STRAND START END SPAN
---------------------------------------------------------------------------------------------------
browser details bulk.comwild 20 77 96 100 100.0% 1 + 1234567 1234568 20
browser details pulp.comwild 20 77 96 100 100.0% 1 + 1234567 1234569 20
browser details gulp.comwild 20 77 96 100 100.0% 1 + 1234568 1234569 20

```

My expected output is

```nohighlight
unix.comwild 1234567 1234568
help.comwild 1234567 1234569
milk.comwild 1234568 1234569
bulk.comwild 1234567 1234568
pulp.comwild 1234567 1234569
gulp.comwild 1234568 1234569

```

Basically, I want to delete the preceding basic information and printing the third, 11th and 12th column from the table. Please keep in mind that the input text is separated by uneven space delimiter. My output can have tab delimited.

Thanks

---

<div class="post-metadata">

**Author:** ![Chubler\_XL](https://community.unix.com/user_avatar/community.unix.com/chubler_xl/32/2077_2.png) [@Chubler\_XL](https://community.unix.com/u/Chubler_XL)\
**Post date:** [August 15, 2012, 4:32pm UTC](https://community.unix.com/t/parsing-text-file/315212/2 "2012-08-15T16:32:36Z")

</div>

Try this:

```nohighlight
awk 'NF>12{print $3,$11,$12 }' OFS='\t' infile

```

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [August 15, 2012, 4:45pm UTC](https://community.unix.com/t/parsing-text-file/315212/3 "2012-08-15T16:45:19Z")

</div>

```nohighlight
awk '/--*$/ {d=1;next} d && !/Home/ {print $3,$11,$12}/Home/{d=0}' OFS='\t' myFile

```

---

<div class="post-metadata">

**Author:** ![jacobs.smith](https://community.unix.com/letter_avatar/jacobs.smith/32/5_5575768a8748004e209b776fc1b2916d.png) [@jacobs.smith](https://community.unix.com/u/jacobs.smith)\
**Post date:** [August 15, 2012, 4:51pm UTC](https://community.unix.com/t/parsing-text-file/315212/4 "2012-08-15T16:51:53Z")

</div>

What if I also want to apply another condition saying that the 8th column/Identity should be 100.0%?

Thanks for ur time.

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [August 15, 2012, 4:59pm UTC](https://community.unix.com/t/parsing-text-file/315212/5 "2012-08-15T16:59:31Z")

</div>

> [@jacobs.smith](#):
>
> What if I also want to apply another condition saying that the 8th column/Identity should be 100.0%?
> 
> Thanks for ur time.

```plaintext
awk '/--*$/ {d=1;next} d && !/Home/ && int($8)==100{print $3,$11,$12}/Home/{d=0}' OFS='\t' myFile

```

You should be able to make the simple changes yourself with 7K posts already...

---

<div class="post-metadata">

**Author:** ![spacebar](https://community.unix.com/user_avatar/community.unix.com/spacebar/32/1679_2.png) [@spacebar](https://community.unix.com/u/spacebar)\
**Post date:** [August 15, 2012, 5:17pm UTC](https://community.unix.com/t/parsing-text-file/315212/6 "2012-08-15T17:17:48Z")

</div>

This will output your 3 columns(space delimited), "t" is your file:

```nohighlight
sed '/^browser/!d' t | awk '{print $3 " " $11 " " $12}'

```

---

<div class="post-metadata">

**Author:** ![Chubler\_XL](https://community.unix.com/user_avatar/community.unix.com/chubler_xl/32/2077_2.png) [@Chubler\_XL](https://community.unix.com/u/Chubler_XL)\
**Post date:** [August 15, 2012, 6:08pm UTC](https://community.unix.com/t/parsing-text-file/315212/7 "2012-08-15T18:08:53Z")

</div>

@vgersh99, OP only has 181 posts, think your looking at you own post count, LOL.

```nohighlight
awk 'NF>12&&$8+0==100{print $3,$11,$12 }' OFS='\t' infile

```

---

<div class="post-metadata">

**Author:** ![vgersh99](https://community.unix.com/user_avatar/community.unix.com/vgersh99/32/14851_2.png) [@vgersh99](https://community.unix.com/u/vgersh99)\
**Post date:** [August 15, 2012, 6:20pm UTC](https://community.unix.com/t/parsing-text-file/315212/8 "2012-08-15T18:20:43Z")

</div>

> [@chubler\_xl](#):
>
> @vgersh99, OP only has 181 posts, think your looking at you own post count, LOL.

true - so \*I\* should be able to make simple changes to my own code 😉
