Extracting logs using gunzip awk and gzip


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting logs using gunzip awk and gzip
# 1  
Old 05-10-2016
Extracting logs using gunzip awk and gzip

Hi All
I am trying to use a hard coded script into shell scripting but I am unable to .
Kindly find the Script below along with the command Please help
Code:
 
 gunzip -c FilePath/FileName_*.gz | awk '$0 > "[04/26/2016][03:30:00.000]" &&  $0 < "[04/26/2016][05:29:59.999]"'|\
 gzip >> FilePath/Outputfile.log.gz



I Am trying to use this in shell script as it is working manually.
Code:
  
 gunzip -c $file*.gz | awk "\$0 > "[$date1][$time]" && \$0 < "[$date3][$time1]"" | \
gzip >> $location

Can you please let me know where am I wrong?

Last edited by vbe; 05-10-2016 at 09:02 AM.. Reason: code tags...
# 2  
Old 05-10-2016
There might be some double quotes missing. What exactly is not working?
# 3  
Old 05-10-2016
I need to take input of Date and Time from the user . It is not picking the correct values.

I have shared the manual line of code which is working and giving me correct response but I am not able to use it in shell script.



I need the below command to be used in shell script with various parameter taken from user

Code:
 gunzip -c FilePath/FileName_*.gz | awk '$0 > "[04/26/2016][03:30:00.000]" &&  $0 < "[04/26/2016][05:29:59.999]"'|\
 gzip >> FilePath/Outputfile.log.gz


parameter Date and Time..


Thanks for the response

---------- Post updated at 08:15 AM ---------- Previous update was at 08:15 AM ----------

Quote:
Originally Posted by RudiC
There might be some double quotes missing. What exactly is not working?
thnx kindly find my query above

Last edited by Don Cragun; 05-10-2016 at 07:58 PM.. Reason: Add CODE tags again.
# 4  
Old 05-10-2016
And how do you want to "take" these parameters from the user?
  1. Will the user give them as command-line arguments?
  2. Do you want your script to prompt the user for all of these arguments?
  3. Are there default values that the user can override with command-line options?
  4. Something else???
What have you tried?
# 5  
Old 05-11-2016
Quote:
Originally Posted by Don Cragun
And how do you want to "take" these parameters from the user?
  1. Will the user give them as command-line arguments?
  2. Do you want your script to prompt the user for all of these arguments?
  3. Are there default values that the user can override with command-line options?
  4. Something else???
What have you tried?
I am taking Input from the user

Code:
echo -n "Enter Start Date in Format YYYYMMDD:"
read date
echo "You Entered : $date"



Code:
gunzip -c "$file_"*.gz | awk '$0 > "$Date $Time" && $0 < "$Date $Time"' | gzip >> "$location" &"

but this is not working $0 is picking the name of the shell script I am running .
I tried using back slash but that is also not working though the value does not get updated.




Code:
 
 initial=[$date1][$time]
  
 final=[$date3][$time1]
  
 Duration="\$0 > \"$initial\" && \$0 < \"$final\"" 
  
 gunzip -c $file*.gz | awk \'$Duration\' | gzip >> $location

Using this the Duration is in proper structure as in the hard coded one.
but while running it is giving error.

It is giving me the below error

==============
awk: '$0

awk: ^ invalid char ''' in expression
==============

What am I doing wrong?
# 6  
Old 05-11-2016
You should get the quotation (singles and doubles) in order, and you should use awk's -v option to pass variables into the program.
# 7  
Old 05-11-2016
In addition to what RudiC has already suggested, you also need to realize that a string in the format you are prompting for (YYYYMMDD) is not going to work well to compare against a string in the format MM/DD/YYYY which is what you said works with your existing pipeline.

And that if the pipeline matching against [04/26/2016][03:30:00.000] (note that there is no space in this pattern) works, then a command that puts a space between the expansion of the Date and Time variables (as in
Code:
gunzip -c "$file_"*.gz | awk '$0 > "$Date $Time" && $0 < "$Date $Time"' | gzip >> "$location" &"

can't work). And, furthermore, if you are reading a variable named date, you need to reference the contents of that variable using $date (NOT $Date).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File name manipulation when extracting from gzip

Hi, Below is the description of my problem. I am trying to loop through the below file names sitting in the file - FileNames.txt, and trying to decompress them FileNames.txt 20150408_MGAC_.txt.gz 20150408_MGCC_.txt.gz 20150408_MGSH__.txt.gz 20150408_MGSL__.txt.gz ... (6 Replies)
Discussion started by: Richmond_CS
6 Replies

2. UNIX for Dummies Questions & Answers

help in extracting logs in readable format

hello everyone. newbie here in unix. I am trying to extract the logs of a certain job and would like to output it in a readable format, see below the CAT part: cat /var/opt/ctma/ctm/sysout/idwesct_sh30_eng_r6_cdcs_sh.LOG_05l0du_000* | egrep -i 'orderid:|file_name=' | sed... (1 Reply)
Discussion started by: eanne_may
1 Replies

3. UNIX for Dummies Questions & Answers

gzip to read logs

Ok here is my trouble. I run scripts whenever I am investigating problems. One of those scripts simply goes to a log folder and runs gzip -cd * | grep error | wc -l This tells me the number of errors in their log's and how much I should pay attention to them. The problem is sometimes... (3 Replies)
Discussion started by: MrEddy
3 Replies

4. UNIX for Dummies Questions & Answers

gzip-gunzip a problem

Hi all, i have a gzipped file. <file_name>.gz . when i try gunzip this file i get, invalid compressed data--format violated this file gzipped like gzip -f -S <file_name> 2 > <error_log_file> there is no error in log. it seems that the file gzipped properly. how this ... (3 Replies)
Discussion started by: dummydba
3 Replies

5. Shell Programming and Scripting

Awk Help for extracting report from logs

Hi I have a log file, with lines of following kind. ------------------------ 2009-05-15 07:49:42,574 INFO - SqlMapObjectDataDao - select - selectObject - 2 ms 2009-05-15 07:49:42,575 INFO - SqlMapUserDao - select - getUserSystemAdminSuperGroup - 0 ms 2009-05-15 07:49:42,576 INFO -... (3 Replies)
Discussion started by: jitendriya.dash
3 Replies

6. Solaris

doubt reg gzip,gunzip

Hi, Can anyone let me explain the difference between tar , uncompress,gzip and gunzip commands. both gzip and gunzip are same i think correct me if am wrong. (1 Reply)
Discussion started by: rogerben
1 Replies

7. UNIX for Dummies Questions & Answers

Cloning OracleHome (gzip/gunzip Help)

Environment: ServerA - IBM AIX 5.2 ServerB - IBM AIX 5.2 I want to clone one of my oracle installation. The easiest way is to ZIP(possibly use gzip) the installed folder from the ServerA (Here Oracle is installed and working fine) , FTP to the ServerB(Here I want to have the installation... (4 Replies)
Discussion started by: aixhp
4 Replies

8. UNIX for Dummies Questions & Answers

gunzip error - not in gzip format

Hi, I am getting this error gunzip file1.tar.Z gunzip: file1.tar.Z: not in gzip format Any clues? This goes bad only in some recent installations of ids (5 Replies)
Discussion started by: eagercyber
5 Replies

9. Shell Programming and Scripting

Extracting data from large logs.

Hi all, I have a large log file that gets created daily. I need to be able to pull text out of the log when I hit a pattern including the 7 lines above it and the 3 lines below and output it to a new text file. Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Pattern Line 9 Line 10... (11 Replies)
Discussion started by: bas
11 Replies

10. HP-UX

decompress in HPUX11 by Gunzip and gzip

Hello evrebody , I have HPUX-11, i try to install "Mozilla" and "unzip utillity" I cannot decompress file (F.tar.gz) or file(F.gz) by commandes: gunzip -dv F.tar.gz | tar -xvf gunzip F.tar.gz or gzip -dv F.tar.gz |tar -xvf gzip F.gz maybe someone know What's the reason? maybe i... (1 Reply)
Discussion started by: yanly64
1 Replies
Login or Register to Ask a Question