Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help with awk using * (asterisk) as the delimiter Post 302759713 by newbie_01 on Tuesday 22nd of January 2013 09:06:33 PM
Old 01-22-2013
Help with awk using * (asterisk) as the delimiter

Hi

I am trying to parse the following lines and has to use * (asterisk) as the delimiter.

These lines are in a file, for example tmp.txt and I am using a while loop


Code:
 
 
tmp.txt:
 
14-OCT-2012 06:38:59 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\ifrun60.EXE)(HOST=8000XXX05004RV)(USER=mickey
))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.90.24.239)(PORT=1552)) * establish * test * 0
14-OCT-2012 06:39:15 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\RWRBE60.exe)(HOST=8000XXX05004RV)(USER=mickey
))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.90.24.239)(PORT=1574)) * establish * test * 0
14-OCT-2012 06:40:48 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\ifrun60.EXE)(HOST=8200XXX138060Z)(USER=mouse))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.217.35.94)(PORT=2525)) * establish * test * 0
14-OCT-2012 07:01:04 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=server911)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=test)(VERSION=135296000)) *
status * 0
 
- while loop code block
 
   while read line
   do
      echo " ---> Parsing ---> "
      echo " - $line"
      echo ""
      timestamp=`echo $line | awk -F* '{ print $1 }'`
      echo " - timestamp = ${timestamp}"
      echo ""
      echo ""
   done < ${pid}.tmp.01

Instead of just getting the timestamp, I am getting the timestamp plus what looks like a directory listing of all files, i.e. like a timestamp and echo * of the directory that I am in.

Can anyone please advise how to get around this?

Feeback/advise much appreciated. Thanks in advance.

---------- Post updated at 09:06 PM ---------- Previous update was at 08:42 PM ----------

Note that the strings are supposed to be one long line of strings so tmp.txt should be as below:

Code:
 
14-OCT-2012 06:38:59 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\ifrun60.EXE)(HOST=8000XXX05004RV)(USER=mickey))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.90.24.239)(PORT=1552)) * establish * test * 0
14-OCT-2012 06:39:15 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\RWRBE60.exe)(HOST=8000XXX05004RV)(USER=mickey))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.90.24.239)(PORT=1574)) * establish * test * 0
14-OCT-2012 06:40:48 * (CONNECT_DATA=(SID=test)(GLOBAL_NAME=test.mydb.com.ch)(CID=(PROGRAM=Z:\Ora6i\BIN\ifrun60.EXE)(HOST=8200XXX138060Z)(USER=mouse))) * (ADDRESS=(PROTOCOL=tcp)(HOST=11.217.35.94)(PORT=2525)) * establish * test * 0
14-OCT-2012 07:01:04 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=server911)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=test)(VERSION=135296000)) * status * 0

 
CUT(1)									FSF								    CUT(1)

NAME
cut - remove sections from each line of files SYNOPSIS
cut [OPTION]... [FILE]... DESCRIPTION
Print selected parts of lines from each FILE to standard output. Mandatory arguments to long options are mandatory for short options too. -b, --bytes=LIST output only these bytes -c, --characters=LIST output only these characters -d, --delimiter=DELIM use DELIM instead of TAB for field delimiter -f, --fields=LIST output only these fields; also print any line that contains no delimiter character, unless the -s option is specified -n with -b: don't split multibyte characters -s, --only-delimited do not print lines not containing delimiters --output-delimiter=STRING use STRING as the output delimiter the default is to use the input delimiter --help display this help and exit --version output version information and exit Use one, and only one of -b, -c or -f. Each LIST is made up of one range, or many ranges separated by commas. Each range is one of: N N'th byte, character or field, counted from 1 N- from N'th byte, character or field, to end of line N-M from N'th to M'th (included) byte, character or field -M from first to M'th (included) byte, character or field With no FILE, or when FILE is -, read standard input. AUTHOR
Written by David Ihnat, David MacKenzie, and Jim Meyering. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for cut is maintained as a Texinfo manual. If the info and cut programs are properly installed at your site, the command info cut should give you access to the complete manual. cut (coreutils) 4.5.3 February 2003 CUT(1)
All times are GMT -4. The time now is 11:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy