The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to get the no. of lines in a text file vimalr Shell Programming and Scripting 8 08-18-2009 02:42 PM
get only some lines from a text file fadista UNIX for Dummies Questions & Answers 1 01-28-2009 06:15 AM
selecting only few lines from many based on a common pattern damansingh Shell Programming and Scripting 2 05-28-2008 06:29 AM
command for selecting specific lines from a script gardasgangadhar UNIX for Dummies Questions & Answers 1 05-13-2008 05:29 AM
Help with selecting specific lines in a large file tansha UNIX for Dummies Questions & Answers 2 02-06-2008 08:26 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-20-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Yep
Code:
awk -F'\]|:' 'NF{line=$0;sub("^ ","",$2);sub(" ","_",$2);file=$2".out";print line >> file;close(file)}'  file
  #2 (permalink)  
Old 08-20-2009
oconmx oconmx is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 9
Excelent !

Thank you again danmero!

---------- Post updated at 10:51 AM ---------- Previous update was at 09:36 AM ----------

Hello Again,

I am using this line:
awk -F'\]|:' 'NF{line=$0;sub("^ ","",$2);sub(" ","_",$2); file="awk/"$2".out"; if ($2 !~ /W|Su|Nag|Fin|Ca|CU|Au|LOG|Loc|G/); print line >> file; close(file); }' file

to remove unwanted types...

now, on my previous script I was converting the [Timestamp] to date and adding ";" as separator piping awk...:

awk '{FS=";"}{gsub(/SERVICE NOTIFICATION: |HOST NOTIFICATION: /,"")}{gsub(/\[1/,"1")}{gsub(/] /,";")}{t=strftime("%m/%d/%Y %T", $1 )}{print t";GMT -7;"w$0}'|awk 'BEGIN {FS=OFS=";"} $6=$7~/^h|^n/?"HOST STATUS;"$6:$6'|awk '{FS=OFS=","}{gsub(/;/,",")}{print $1","$2","$3","$4","$5","$6","$7","$8",\""$9 $10 $11 $12 $13 $14 $15 $16 $17"\""}'

Is there any easy way to remove the [] from the timestamp, convert it to time and change the , to ; .... as you can see I am not that good at awk; so any advise is highly appreciated, to avoid piping commands.

Regards,
Oconmx
  #3 (permalink)  
Old 08-20-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
To keep the forums high quality for all users, please take the time to format your posts correctly.
  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

Quote:
Originally Posted by oconmx View Post
to remove unwanted types...
.......
now, on my previous script I was converting the [Timestamp] to date and adding ";" as separator piping awk...:
.......
Is there any easy way to remove the [] from the timestamp, convert it to time and change the , to ; .... as you can see I am not that good at awk; so any advise is highly appreciated, to avoid piping commands.
Look like you are walking backward.
First you generate a file and now you try to fixit. Maybe you should generate the original file the way you like it from the beginning?
  #4 (permalink)  
Old 08-21-2009
oconmx oconmx is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 9
Thank you Danmero,

The problem is that I dont understand your code very well, I haven't been able to use change the lines on the fly, before they are sent to the file.

I will keep trying. Thank you!
Reply

Bookmarks

Tags
csv, log, perl, script, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:15 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0