Derive date and its Volume number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Derive date and its Volume number
# 1  
Old 07-01-2017
Derive date and its Volume number

Hi All,
I have a list of date number (YYYYMMDD) and its own number in a file.
Here is the example

Code:
20170320
D100001
D100002
D100003
20170321
D200001
D200002
D200004
D200005
20170322
D200005
D200006
D200007

If I grep a date ie. 20170321, I expecting to get the following list
D200001
D200002
D200004
D200005

Once it found next first integer, it will need to stop from proceeding.

Thank You everyone.
# 2  
Old 07-01-2017
Hello ckwan123, Could you please try following and let me know if this helps you.
Code:
 awk '/^[0-9]/{val=""} /20170321/{val=1;next} val' Input_file

Thanks, R. Singh

Last edited by RavinderSingh13; 07-01-2017 at 11:21 AM..
# 3  
Old 07-01-2017
Not as elegant as intended, but try
Code:
awk '$0+0 == $0 {P = 0} $0 == SRCH {P = 1; next} P' SRCH=20170321 file
D200001
D200002
D200004
D200005

# 4  
Old 07-04-2017
Thanks Ravin and RudiC. However, I feel RudiC provided solution is easier to apply into my requirement as it is more flexible by replace the date with a variable. Ravin, yours is able to run with constant value, do you think it can change it to variable ?
RudiC, could you briefly your command ? Thanks so much for your given valuable solution.
# 5  
Old 07-04-2017
Well, if it finds the search phrase, it set the boolean variable P to 1. P is evaluated, and if TRUE (or 1), the line is printed (awk default behaviour). Later, if an integer is found ($0+0 casts the line to a number or (roughly speaking) to something different if a non-number ist encountered), P is reset to 0 and printing stops.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Red Hat

No space in volume group. How to create a file system using existing logical volume

Hello Guys, I want to create a file system dedicated for an application installation. But there is no space in volume group to create a new logical volume. There is enough space in other logical volume which is being mounted on /var. I know we can use that logical volume and create a virtual... (2 Replies)
Discussion started by: vamshigvk475
2 Replies

2. UNIX for Dummies Questions & Answers

Confusion Regarding Physical Volume,Volume Group,Logical Volume,Physical partition

Hi, I am new to unix. I am working on Red Hat Linux and side by side on AIX also. After reading the concepts of Storage, I am now really confused regarding the terminologies 1)Physical Volume 2)Volume Group 3)Logical Volume 4)Physical Partition Please help me to understand these concepts. (6 Replies)
Discussion started by: kashifsd17
6 Replies

3. Shell Programming and Scripting

How to derive the last Sunday's date when Current date value is passed

Hi All, I have a requirement in my project where a batch runs on any day of a week. The input files will land to the server every Sunday. I need to read these files based on the current BUS_DAY (which falls any day of the week). For e.g : if the BUS_DAY is 20120308, we need to derive the... (3 Replies)
Discussion started by: dsfreddie
3 Replies

4. Shell Programming and Scripting

Derive the Year value from the date value

Hi All, I have two dates: PREVIOUS_DAY and CURRENT_DAY. I need to test the these two values years are same or not. PREVIOUS_DAY like '%y%m%d' i.e values like 111010, 111011, 111012 etc. For CURRENT_YEAR:'date +%Y' use this command. How can derive the year value from PREVIOUS_DAY and... (1 Reply)
Discussion started by: pdathu
1 Replies

5. Shell Programming and Scripting

Number of days between the current date and user defined date

I am trying to find out the number of days between the current date and user defined date. I took reference from here for the date2jd() function. Modified the function according to my requirement. But its not working properly. Original code from here is working fine. #!/bin/sh... (1 Reply)
Discussion started by: hiten.r.chauhan
1 Replies

6. AIX

Basic Filesystem / Physical Volume / Logical Volume Check

Hi! Can anyone help me on how I can do a basic check on the Unix filesystems / physical volumes and logical volumes? What items should I check, like where do I look at in smit? Or are there commands that I should execute? I need to do this as I was informed by IBM that there seems to be... (1 Reply)
Discussion started by: chipahoys
1 Replies

7. Shell Programming and Scripting

Derive date from a calendar

I'm using AutoSys as scheduler for my application. I maintain a calendar in AutoSys which specifies when a job should run. A unix shell scripts runs on the days spceified by calendar and processes incoming files. These incoming files contain dates embedded in the filenames. My job needs to... (2 Replies)
Discussion started by: autouser123
2 Replies
Login or Register to Ask a Question