# Display all lines after a matching variable

**URL:** <https://community.unix.com/t/display-all-lines-after-a-matching-variable/358262>\
**Category:** Shell Programming and Scripting\
**Created:** [February 2, 2016, 2:35am UTC](https://community.unix.com/t/display-all-lines-after-a-matching-variable/358262 "2016-02-02T02:35:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nagesh\_1985](https://community.unix.com/user_avatar/community.unix.com/nagesh_1985/32/3701_2.png) [@Nagesh\_1985](https://community.unix.com/u/Nagesh_1985)\
**Post date:** [February 2, 2016, 2:35am UTC](https://community.unix.com/t/display-all-lines-after-a-matching-variable/358262/1 "2016-02-02T02:35:38Z")

</div>

Hi,

I have a file called `abc.txt` with the following dates

```nohighlight
2016-01-27
2016-01-28
2016-01-29
2016-01-30
2016-01-31
2016-02-01
2016-02-02
2016-02-03

```

I would like to print all lines below if `2016-01-31` is found, excluding that date.  
I use this command --\>

```nohighlight
sed '1,/2016-01-31/d' abc.txt

```

If i declare the date in a variable and then try this, its not working. How do I include the variable in the sed command in Linux.

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://community.unix.com/letter_avatar/ravindersingh13/32/5_5575768a8748004e209b776fc1b2916d.png) [@RavinderSingh13](https://community.unix.com/u/RavinderSingh13)\
**Post date:** [February 2, 2016, 3:09am UTC](https://community.unix.com/t/display-all-lines-after-a-matching-variable/358262/2 "2016-02-02T03:09:14Z")

</div>

Hello Nagesh\_1985,

Please use code tags as per forum rules for commands/inputs/codes which you are using in your posts.  
Could you please try following and let me know if this helps you.

```nohighlight
awk '($0 ~ /2016-01-31/){A=1;next} A{print}' Input_file

```

Output will be as follows.

```nohighlight
2016-02-01
2016-02-02
2016-02-03

```

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [February 2, 2016, 3:38am UTC](https://community.unix.com/t/display-all-lines-after-a-matching-variable/358262/3 "2016-02-02T03:38:35Z")

</div>

Try double quoting:

```nohighlight
DT=2016-01-31
sed "1,/$DT/d" file
2016-02-01
2016-02-02
2016-02-03

```

---

<div class="post-metadata">

**Author:** ![MadeInGermany](https://community.unix.com/letter_avatar/madeingermany/32/5_5575768a8748004e209b776fc1b2916d.png) [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Post date:** [February 2, 2016, 4:43am UTC](https://community.unix.com/t/display-all-lines-after-a-matching-variable/358262/4 "2016-02-02T04:43:22Z")

</div>

> [@ravindersingh13](#):
>
> Hello Nagesh\_1985,
> 
> Please use code tags as per forum rules for commands/inputs/codes which you are using in your posts.  
> Could you please try following and let me know if this helps you.
> 
> ```plaintext
> awk '($0 ~ /2016-01-31/){A=1;next} A{print}' Input_file
> 
> ```
> 
> Output will be as follows.
> 
> ```plaintext
> 2016-02-01
> 2016-02-02
> 2016-02-03
> 
> ```
> 
> Thanks,  
> R. Singh

In short

```plaintext
awk 'A; /2016-01-31/{A=1}' Input_file

```

All these solutions require the searched string to be present.  
Here is one with a string comparison (that of course requires a sorted input)

```plaintext
awk '($0"" > "2016-01-31")' Input_file

```

---

<div class="post-metadata">

**Author:** ![Nagesh\_1985](https://community.unix.com/user_avatar/community.unix.com/nagesh_1985/32/3701_2.png) [@Nagesh\_1985](https://community.unix.com/u/Nagesh_1985)\
**Post date:** [February 2, 2016, 5:21pm UTC](https://community.unix.com/t/display-all-lines-after-a-matching-variable/358262/5 "2016-02-02T17:21:10Z")

</div>

The command worked !!
