Need Awk command to get part of string based on delimeter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Awk command to get part of string based on delimeter
# 1  
Old 08-28-2010
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.
# 2  
Old 08-28-2010
Code:
awk -F"|" '{print $1}' input

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 08-28-2010
Try:
Code:
awk -F "|" '{print $1}' <inputfile

This User Gave Thanks to agama For This Post:
# 4  
Old 08-28-2010
shell

If your value is in a variable, the shell builtin can:
Code:
~$ S="15:29:15 28.08.2010|SCHEDULE: Started program POSG1"
~$ echo ${S%|*}
15:29:15 28.08.2010

This User Gave Thanks to frans For This Post:
# 5  
Old 08-28-2010
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.
# 6  
Old 08-28-2010
Code:
awk -F"|" '{$2=gensub(".*\\(.+ ([^)]+)\\).*","\\1",1,$2);print $1,$2}' file

This User Gave Thanks to bartus11 For This Post:
# 7  
Old 08-28-2010
It's Working... but need to research ur command dude. Smilie 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"]

Last edited by Scott; 08-28-2010 at 07:01 PM.. Reason: Removed "bump"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - how to compare part of the string?

Need help for awk.. file will have comma separated numbers, I need check digits before 10 numbers eg ( 001)1234567890 Basically want to check country code of a mobile number. eg: abc,def,data, data,0011234567890, data,data Script should be checking country code with 001, I will pass... (10 Replies)
Discussion started by: vegasluxor
10 Replies

2. Shell Programming and Scripting

Match part of string in file2 based on column in file1

I have a file containing texts and indexes. I need the text between (and including ) INDEX and number "1" alone in line. I have managed this: awk '/INDEX/,/1$/{if (!/1$/)print}' file1.txt It works for all indexes. And then I have second file with years and indexes per year, one per line... (3 Replies)
Discussion started by: phoebus
3 Replies

3. Shell Programming and Scripting

Grep a part of file based on string identifiers

consider below file contents cat myOutputFIle.txt 8 CCM-HQE-ResourceHealthCheck: Resource List : No RED/UNKNOWN resource Health entries found ---------------------------------------------------------- 9 CCM-TraderLogin-Status: Number of logins: 0... (4 Replies)
Discussion started by: vivek d r
4 Replies

4. Shell Programming and Scripting

Put delimeter in data based on value

Hi Friends, I have a file as below source.txt 12345JackYKing32N 1235 JulyYoig 31N i am using cut command for cutting the fields cut -c 1-5 source.txt 12345 1235 like above i have to use each time to cut all the fieds manually. I have a file(pre.txt) which tells... (3 Replies)
Discussion started by: i150371485
3 Replies

5. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

6. Shell Programming and Scripting

AWK Command parse a file based on string.

AWK Command parse a file based on string. I am trying to write a shell script to parse a file based on a string and move the content of the file to another file. Here is scenario. File content below Mime-Version: 1.0 Content-Type: multipart/mixed; ... (2 Replies)
Discussion started by: aakishore
2 Replies

7. Web Development

split line based on delimeter SQL

I have a SQL query SELECT BLAH_ID, BLAH_CODE, DATEFORMAT(CALENDAR_DATE, 'MM-DD-YYYY') AS CALENDAR_DATE_STR, HOURS, 'N', FROM blah_tmp_tbl order by CALENDAR_DATE_STR,BLAH_ID,BLAH_CODE; OUTPUT TO 'MyExport.CSV' quote '' FORMAT ASCII; That gets me the below output; ... (2 Replies)
Discussion started by: ffdstanley
2 Replies

8. Shell Programming and Scripting

How to merge 2 files based on delimeter in perl?

Hi, I have 2 files. a.txt & b.txt # a.txt contains the following text. apple grapes # b.txt contains the following text. banana pine My question is. (1 Reply)
Discussion started by: vanitham
1 Replies

9. Shell Programming and Scripting

How to get part of string in awk from match

Hi, Im an awk noob and I am having trouble trying to get matches. Here is my script: #!/bin/gawk -f BEGIN {} $0 ~ /<a href=".*">.*<\/a>/{print} Ideally I want to be able to get the actual link and print it. In PHP you can do preg_replace and get the match you want by using \\1 where 1... (2 Replies)
Discussion started by: adsyuk
2 Replies

10. Shell Programming and Scripting

sort entire line based on part of the string

hey gurus, my-build1-abc my-build10-abc my-build2-abc my-build22-abc my-build3-abc basically i want to numerically sort the entire lines based on the build number. I dont zero pad the numbers because thats "how it is" ;-) sort -n won't work because it starts from the beginning. ... (10 Replies)
Discussion started by: gurpal2000
10 Replies
Login or Register to Ask a Question