Hi,
I have a file called abc.txt with the following dates
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 -->
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.
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.
awk '($0 ~ /2016-01-31/){A=1;next} A{print}' Input_file
Output will be as follows.
2016-02-01
2016-02-02
2016-02-03
Thanks,
R. Singh
RudiC
February 2, 2016, 3:38am
3
Try double quoting:
DT=2016-01-31
sed "1,/$DT/d" file
2016-02-01
2016-02-02
2016-02-03
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.
awk '($0 ~ /2016-01-31/){A=1;next} A{print}' Input_file
Output will be as follows.
2016-02-01
2016-02-02
2016-02-03
Thanks,
R. Singh
In short
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)
awk '($0"" > "2016-01-31")' Input_file