Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Read a file with zcat


    Hi,
    I have some log in .gz format and I use the zcat to decompress.
    I want to read the file line by line, and after making some changes to the lines I create a new file.
    Code:
    while read -r line
    .      do
     ....changes to the lines... 
    
    done <'zcat nome.log.data'
    I get the following error on zcat: No such file or directory
    How can I do?
    Thanks so much!

  2. #2
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,456
    Hi, meme_14.

    Welcome and thanks for posting your attempt.

    See page Process Substitution and specifically Example 23-1.

    Keep that link around, it's a long document, full of examples.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  3. #3
    could you post a working example please?
    i'm not 100% sure what you're doing there.

    +1 for code tags!
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire
    You can post a link by removing "http://www." from it.

  4. $spacer_open
    $spacer_close
  5. #4
    Quote Originally Posted by nihili View Post
    could you post a working example please?
    i'm not 100% sure what you're doing there.

    +1 for code tags!
    Hi,
    I have some log files in .gz format. I want change some fields in this log and I want create a new log file with this change.

    I try to read the logs line by line with the 'while command' but it doesn't work with the .gz format.

    Code:
     while read -r line
         do
           l="$line" 
           echo "$(date -d "${l:0:4}" +%d/%b/%Y)" >> newfile
          done < "$path/namefile.log.date.gz"
    The problem is in the 'done' and in the .gz file. I try tha zcat but it doesn't work.
    How can I do?
    Thanks a lot!

  6. #5
    Thanks a lot! I will read it!

  7. #6
    Code:
    #!/bin/bash
    path="/var/log/some.log.gz"
    while read -r line
    do
    	echo "$(date -d "${line:0:4}" +%d/%b/%Y)" >> newfile
    done <<<"$(zcat $path)"
    this works for me.
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire
    You can post a link by removing "http://www." from it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •