Need Awk command to get part of string based on delimeter

HI,

Need awk command to get date and time alone from

Input : "15:29:15 28.08.2010|SCHEDULE: Started program POSG1"

Output expected : "15:29:15 28.08.2010"

Please help.

awk -F"|" '{print $1}' input
1 Like

Try:

awk -F "|" '{print $1}' <inputfile
1 Like

If your value is in a variable, the shell builtin can:

~$ S="15:29:15 28.08.2010|SCHEDULE: Started program POSG1"
~$ echo ${S%|*}
15:29:15 28.08.2010
1 Like

Thanks All. These info are in a file. I need one more help.

Input : "07:08:43 28.08.2010|SCHEDULE: Started program POSG1[(0600 08/28/10)] has completed successfully"

Needed output : "07:08:43 28.08.2010 08/28/10"

Note : 08/28/10 is from [(0600 08/28/10)].

Need a single awk command folks. Thanks in advance.

awk -F"|" '{$2=gensub(".*\\(.+ ([^)]+)\\).*","\\1",1,$2);print $1,$2}' file
1 Like

It's Working... but need to research ur command dude. :wink: Thanks a bunch.

---------- Post updated at 04:16 PM ---------- Previous update was at 04:02 PM ----------

Sorry , I edited th eline to make it simple. My actual input

Input : "06:28:45 28.08.2010|SCHEDULE: Started program POSG1[(0600 08/27/10),(0AAAAAAAAAAAOG66)].PLK110 (#J2325) has completed successfully"

Output :07:08:43 28.08.2010 08/28/10

The awk command given is fetching "07:08:43 28.08.2010 (#J2325"

Please help. Sorry about last time[COLOR="\#738fbf"]

awk -F"|" '{$2=gensub(/.*([0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]).*/,"\\1",1,$2);print $1,$2}' file
string="Input : "07:08:43 28.08.2010|SCHEDULE: Started program POSG1[(0600 08/28/10)] has completed successfully""
f="${string%%|*}"
r=${string%)\]*}
r=${r##*\[(* }
final="$f $r"
awk -F '[| \t")]*' '{print $2,$3,$8}' infile