Hi,
I'm very new to UNIX scripting and find quite difficult to understand simple UNIX syntax. Really appreciat if somebody could help me to give simple codes for my below problems:-
1) I need to search for a string "TTOH 8031950001" in a files which filename will be "*host*'. For example, the string I searceh found in below line:-
<Jun 30, 2010 5:06:59 PM GMT+08:00> <DEBUG> <MessageFormatter> {F5380112-1890-3589-1A9E-7F135D382013} sending [ CAMSTTOH TTOH 8031950001 53020001706590000 000001 6 009 21403500125671 ENG AUN CHAN Y 00257600006 ENG AUN CHAN 3445456567 ANANDA KRISHNAN N 100002322 20100630 N N 000000000200000 000000000000200 000000000200200 10125 CAMS21301000007960 10063002024620002 N 000000000000000 ]
(Please consider above is in a single line)
2) The line is too long. I just need Item in the position 2 to 14, Items in {}, sending until end of line.
Jun 30, 2010 F5380112-1890-3589-1A9E-7F135D382013 sending [ CAMSTTOH TTOH 8031950001 53020001706590000 000001 6 009 21403500125671 ENG AUN CHAN Y 00257600006 ENG AUN CHAN 3445456567 ANANDA KRISHNAN N 100002322 20100630 N N 000000000200000 000000000000200 000000000200200 10125 CAMS21301000007960 10063002024620002 N 000000000000000 ]
Then, it will be in a formatted text file.
Anyone can help to come out with a script?
Thanks in advance..
Note:-
1)I attached sample of files to be search - batch-host.log.6
2)I attached sample expected output file.
hi rdc, thx for your prompt reply. i got "awk: Input line <Jun 29, 2010 5:24:3 cannot be longer than 3,000 bytes.
The input line number is 1. The file is batch-host.log.6.
The source line number is 1." message when running the script u provided. I tried to use below script instead:-
Looks you saw my old post before I updated to awk command? I used cut first, because it is easy to get column 2 to 14, but seems there are more spaces between each column. such as "TTOH 8031950001" has 3 spaces between them. That's why I updated to awk command.
What you can do now is, adjust the range, maybe from 2 to 20 or something else.
For the awk command, I test succesfully in my system with your file batch-host.log.6. If your system is solaris, use /usr/bin/nawk or /usr/xpg4/bin/awk