- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- please help with kshell script..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2006 06:37 PM
12-10-2006 06:37 PM
1234561|2007|2|28
4567891|2007|3|31
7897891|2007|4|5
9879871|2007|5|30
2578961|2007|6|25
...
..
.
where $2 is year $3 is month and $4 is day..
considering if today is 30may2007 I heed to have on my other file just one line:
9879871|2007|5|30
is that possible to bo done in ksh pleasee..
thanks a lot...
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2006 06:59 PM
12-10-2006 06:59 PM
Re: please help with kshell script..
how about:
grep -e '|2007|5|30' datafile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2006 07:21 PM
12-10-2006 07:21 PM
Re: please help with kshell script..
or for a more generic solution:
#!/usr/bin/ksh
grep -e "$1|$2|$3" datafile
$ ./b.sh 2007 5 30
9879871|2007|5|30
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2006 07:44 PM
12-10-2006 07:44 PM
Re: please help with kshell script..
$ cat ./extract.sh
#!/usr/bin/sh
if [ $# != 4 ]
then
THIS_YEAR=$(date +%Y)
THIS_MONTH=$(date +%m)
THIS_DAY=$(date +%d)
MONTH=$(echo ${THIS_MONTH#0})
DAY=$(echo ${THIS_DAY#0})
grep "$THIS_YEAR|$MONTH|$DAY" $1
else
grep "$1|$2|$3" $4
fi
Try running it like this:
$ ./extract.sh 2007 2 28 ./infile
1234561|2007|2|28
or wait till the end of February and run it without parameters...
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2006 07:55 PM
12-10-2006 07:55 PM
Re: please help with kshell script..
I assume u want to get only the line corresponding to today's date
in other file.
If so then try this
$ awk -F \| -v a=`date "+%Y"` -v b=`date "+%m"` -v c=`date "+%d"` '$2==a&&$3==b&&$4==c {print $1}'
Thats all
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2006 08:20 PM
12-10-2006 08:20 PM
Re: please help with kshell script..
Sorry for a small mistake,
Pl. replace {print $1} with {print $0}
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 01:00 AM
12-11-2006 01:00 AM
Re: please help with kshell script..
1111119|2007|3|31
if dodays date is april 30 I need to take that line as well as a result..
for example: today is 28 feb 2007 I need to test next date..if next date is 1.something.2007 I need to have
that line as result as well..
for example if I have:
1111119|2007|2|28
1111119|2007|4|30
1111119|2007|12|31
1111119|2007|8|8
and let assume that today is june 30 2007 as an output I should have:
1111119|2007|2|28
1111119|2007|4|30
1111119|2007|12|31
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 01:09 AM
12-11-2006 01:09 AM
Re: please help with kshell script..
Can you please state your EXACT requirements?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 01:41 AM
12-11-2006 01:41 AM
Re: please help with kshell script..
but if today is for example june 30, 2007
and my input file is like this:
8111319|2007|2|28
1112119|2007|4|30
7111119|2007|12|31
1231119|2007|8|8
script should check if next day is 1st in the month and output this:
8111319|2007|2|28
1112119|2007|4|30
7111119|2007|12|31
becouse february has 28 days...if today is for example 8 sept or 8 dec or any other month output should be like this:
1231119|2007|8|8
that means if I have bigger file:
1234561|2007|2|28
4567891|2007|3|31
7897891|2007|4|5
9879871|2007|5|30
1578961|2007|6|28
1897893|2007|10|28
7879871|2007|12|30
9578962|2007|12|28
and today is 28 of august:
output should be like this:
1234561|2007|2|28
1578961|2007|6|28
1897893|2007|10|28
9578962|2007|12|28
that means does not metter which month is it looks fot day..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 01:48 AM
12-11-2006 01:48 AM
Re: please help with kshell script..
1) If the current day is the LAST DAY of the month, then look in the file for ANY LINES from the current year that occur on the last day of their respective months.
2) If the current day is some other time in the month, then look for lines from the current year from any month where the day equals today.
Is that accurate?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 02:35 AM
12-11-2006 02:35 AM
Re: please help with kshell script..
In point 1..
if I have in my file line like this:
....
..
2222228|2007|2|28
5656569|2007|1|31
...
..
and today is 31 of march 2007 I want both lines to be in my result file.
or if I have line like this:
....
..
2123221|2007|8|31
5633561|2007|9|30
...
..
and today is for example 30 november 2007 (last day in november)
then both lines should be in result file..
I tryed with some greps..but if does not results way I want..
THANK U for patience..
cheers,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 04:57 AM
12-11-2006 04:57 AM
Re: please help with kshell script..
your original request can be done easy. You have to keep in mind to escape the pipe symbol when it's NOT used as a syntax element (OR) in a pattern definition:
awk -v ym=$(date '+%Y|%m|%d') -F'|' 'BEGIN {split(ym,z,"|");lookfor="\\|"z[3]"$"}
$0 ~ lookfor {if($(NF-1) != z[2]) print}' inputfile
Your extended request regarding the last day of a month requires much more work.
Let's see, if I find it interesting enough to formulate it ...
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 05:39 AM
12-11-2006 05:39 AM
Solutionits your turn to test this :-)
- I contruct a RE which is created+set dynamically to the date input.
- You have take the year into account, because of the leap year computation for february.
- To get no output for the current month at the last day of a month is left as an exercise.
awk -v ym=$(date '+%Y|%m|%d') 'BEGIN {split(ym,z,"|");stdlook="\\|"z[3]"$"
lof[1]=31;
if(z[1]%4) lof[2]=28
else lof[2]=29
lof[3]=31
lof[4]=30
lof[5]=31
lof[6]=30
lof[7]=31
lof[8]=31
lof[9]=30
lof[10]=31
lof[11]=30
lof[12]=31
lmonstr="\\|1\\|31$"
for(i=2;i<13;i++) lmonstr=lmonstr"|\\|"i"\\|"lof[i]"$"
print "lmonstr: ",lmonstr
if(z[3]==lof[z[2]]) lookup=lmonstr
else lookup=stdlook
}
$0 ~ lookup' inputfile
mfG Peter
The test the last month computation, use
awk -v ym='2006|12|31' ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2006 07:01 AM
12-11-2006 07:01 AM
Re: please help with kshell script..
try this, using your input file as $1...
#!/usr/bin/sh
LAST_DAY_OF_MONTH=no
THIS_MONTH=$(date +%m)
THIS_DAY=$(date +%d)
MONTH=$(echo ${THIS_MONTH#0})
DAY=$(echo ${THIS_DAY#0})
case $THIS_MONTH in
1|3|5|7|8|10|12)
if [ "$THIS_DAY" = "31" ]
then
LAST_DAY_OF_MONTH=yes
fi
;;
4|6|9|11)
if [ "$THIS_DAY" = "30" ]
then
LAST_DAY_OF_MONTH=yes
fi
;;
2)
;;
4|6|9|11)
if [ "$THIS_DAY" = "30" ]
then
LAST_DAY_OF_MONTH=yes
fi
;;
2)
if [ "$THIS_DAY" = "28" -o "$THIS_DAY" = "29" ]
then
LAST_DAY_OF_MONTH=yes
fi
;;
esac
if [ "$LAST_DAY_OF_MONTH" = "yes" ]
then
grep -E "\|2\|28$|\|1\31$|\|3\|31$|\|4\|30$|\|5\|31$|\|6\|30$|\|7\|31$|\
|8\|31$|\|9\|30$|10\|31$|11\|30$|12\|31$" $1
else
grep "|${THIS_DAY}"$ $1
fi
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2006 06:17 PM
12-12-2006 06:17 PM
Re: please help with kshell script..
I got this:
grep: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2006 07:38 PM
12-12-2006 07:38 PM
Re: please help with kshell script..
if your system does not like "grep -E", try using a number of "grep -e"s instead, e.g.:
grep -e "\|2\|28"$ -e "|\|1\31"$ -e "|\|3\|31"$ -e "|\|4\|30"$ -e "|\|5\
|31"$ -e "|\|6\|30"$ -e "|\|7\|31"$ -e "|\|8\|31"$ "|\|9\|30"$ "|10\|31"$ -e "|1
1\|30"$ -e "|12\|31$" $1
regards,
John K.