while read line
do
but getting output as
temp.ksh[35]: Thu Jan 29 15:01:17 CST 2015: not found [No such file or directory]
I should get output as 15:01:17
You can't have a space between the variable= and the value to be assigned to that variable. The syntax you used, sets st to an empty string and includes it in the environment of the command that follows. But that won't get rid of the Thu Jan 29 or the CST 2015
Note that your original post didn't say anything about the string started at appearing in the input (and was not in your sample input).
Assuming you're working in an English locale, you could try something like:
The ERE can be simplified if you only have 24-hour format times.
With the following contents in your input file:
it produces the output:
Fairly simple changes would allow you to find more than one timestamp on a line.
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk
Last edited by Don Cragun; 01-30-2015 at 07:32 PM..
Reason: Fix typo (s/value/variable/).
This User Gave Thanks to Don Cragun For This Post:
Hi Ravinder, --re-interval (or --posix) is needed on gawk to get POSIX conforming EREs, but it is not needed for any version of awk that conforms to the POSIX standards.
The output that I showed in post #8 was the exact output produced by the awk command I showed in that thread when it was run on OS X Yosemite.
Solution 1:
Option 2:
What you asked in first post, and what you described your post #7 does not match.
You're looking for the string "started at" but your example post #1, shows us there is only "start at".
If you care about the status, feel free to add a check for "vStatus", wether its "start" or "end".
If the string is allways the same structure, then you can do something like this:
This will probably work for about half of a year's input assuming that all lines are in exactly the same format and that the CST is referring to US Central Standard timezone. It won't work when dayligth savings time is in effect. And, of course, it will only work for dates in 2015.
The following modifications should work year around for the sample input provided in 2015:
The ? will match any character; the [DS] will match an uppercase D or an uppercase S. I will leave the modifications needed to recognize additional years as an exercise for the reader. If some of the dates being processed come from other timezones, I would suggest using a different approach.
Quote:
Originally Posted by senhia83
try
You seem to be mixing the awk match() and split() functions. But, I get a syntax error when I try this code. The match() function takes two arguments (string to be matched and an ERE to match) and sets various awk variables to indicate whether or not a match was found and, if there was a match, the starting position of the match and the length of the match. The awk script I suggested in post #8 in this thread uses match() this way.
The awk split() function creates an array of values corresponding to values separated by field separators specify by an ERE. With the ERE you use, the desired date would not appear in the array at all since the ERE selects the date as the field separator.
This User Gave Thanks to Don Cragun For This Post:
Hi All, Thanks for replying. I tried Bigsanch's code modified by Don(#12). It worked fine for me. However need to do a thorough testing before implementing.
Also my original code wrked after removing the extra space after =(#8). But I am getting Thu Jan 29 15:01:17 CST 2015 in a variable. So I was looking if anyways I can extract only the time from the above.
Hi All, Thanks for replying. I tried Bigsanch's code modified by Don(#12). It worked fine for me. However need to do a thorough testing before implementing.
Also my original code wrked after removing the extra space after =(#8). But I am getting Thu Jan 29 15:01:17 CST 2015 in a variable. So I was looking if anyways I can extract only the time from the above.
The "from the above" is a little ambiguous. There are suggestions above in this thread from several volunteers trying to help you, most of which try to just extract a timestamp from your sample data.
What operating system and shell are you using? As has been pointed out, some of the suggestions above will work on some systems but not on others.
Instead of just giving us two strings to parse, describe the strings you want to parse:
Will the timezone always be CST? Always CST or CDT? Always US timezones?
What range of years do you need to cover?
Are you looking for a 24hr time only or can there be 12hr times (with AM or PM) as well?
Is the date in your string always preceded by the literal string a.sh start time is? Why is there a space in front of that sometimes? If not, describe what will appear (number of words, anything containing a colon (:), etc.).
Hello.
First best wishes for everybody.
here is the input file ("$INPUT1") contents :
BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY;
BASH_FUNC_message_debug%%=() { local -a L_ARRAY;
BASH_FUNC_message_end_script%%=() { local -a L_ARRAY;
BASH_FUNC_message_error%%=() { local... (3 Replies)
I'm somewhat new to shell scripting and I have a file that had a date in it.
/somedirectory/datefile.txt
I want to take the date in the file: 2013-06-12
and change the formate to 20130612 and have it as a variable/parm
I also what to take that date 2013-06-12
and substring it.
I know... (3 Replies)
Good morning friends,
how can i remove a string with linux scripting from a file? In specific i want to remove from a file all the tweet names and links
eg
@aerta and links such as http://dst.co/pIiu3i9c
Thanx!!! (4 Replies)
Hello
I am trying to substring the month in a date string
I am getting an error " bad substitution"
#!/bin/ksh
INPUT='20121225'
echo ${$INPUT:5:2}
exit 0
Very new in unix.
Thanks.
Please use code tags next time for your code and data. (9 Replies)
Hi,
I have an input string say for example:
ABC,DEF,IJK,LMN,...,XYZ
The above string is comma delimited. Now I have to extract the last part after the comma i.e. XYZ.
:b: (3 Replies)
Hi All,
Problem Description:
XML_REP_REQUEST=`CONCSUB "$LOGIN" "SQLAP" "$RESP_NAME" "$USRNM" WAIT="Y" "CONCURRENT" "APPLICATION_SHORT_NAME"
"CP_SHORT_NAME"`
echo Report Request: $XML_REP_REQUEST --to print value in log file
While execution the value of 'XML_REP_REQUEST' is 'Prozess... (5 Replies)
hi all,
I am trying to extract SUBSTRINGS out of a string using ksh.
The string is "SAPR3K.FD0.FA.TJ.B0010.T050302"
I tried using
a= `expr substr $stringZ 1 2`
which is giving me a syntax error, donno why??
any ideas why its not working??
I also tried
echo "welcome" | awk '{... (3 Replies)