The OP says that sed leaves a \n in the "empty file". So its size will be 1 byte and your test will show not empty.
You could also use the stat command:
The stat command is not standard, and there are different versions:
---------- Post updated at 06:49 PM ---------- Previous update was at 06:48 PM ----------
Quote:
Originally Posted by plawr
I have a program that takes a file in which I use a sed to remove some data that is not needed. If all of the data is removed. I want to grep for that in the file and print that there is no data left in the file. When I use sed, I replace a word with nothing but it still seems to leave a return carriage. Please give me some ideas on how to do this. Thanks!
Fix the sed command to delete the line instead of just the word.
AIX 5.3 / KSH
I have a Java application which creates a log file a.log. I have a KSH script which does the following action
cp a.log /directory2/b.log
> a.log
After this the file size goes to 0 as per "ls -l"
Then next time when the application writes into this file, the file size... (4 Replies)
Hi All,
I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both.
The value of $? is coming 0 in if part also and else part too.
#!/bin/ksh
if ]; then
echo "data"
# exit 0
echo "$?"
else... (4 Replies)
Hi everyone.
I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this:
ID: 20
Name: X
Age: 19
ID: 21
Name: Z
ID: 22
Email: xxx@yahoo.com
Name: Y
Age: 19
I want to grep records that... (4 Replies)
Hi Expert,
Kindly request for your expertise in this matter.
I have below output:
12.125.124.173,xx1.common.com
12.125.124.174,xx2.common.com
12.125.124.175,xx3.common.com
12.125.124.176,
12.125.124.177,
12.125.124.178,
12.125.124.179,xx4.common.com
12.125.124.180,xx5.common.com... (8 Replies)
Hi there,
I'm just starting out with shell scripting and I'm trying to make a test where the script will basically run yum check-update to find out if the server has any available and if it does it e-mails me but if not it will just stop there.
I have it working if there are actually... (7 Replies)
Suppose i have the following data :
cat file.txt
12431,123334,55353,546646,14342234,4646,35234
123123,3535,123434,132535,1234134,13535,123534
123213,545465,23434,45646,2342345,4656,31243
2355425,2134324,53425,342,35235,23434,234535
3423424,234234,65465,,2344,35436,234524,234... (7 Replies)
Hi,
I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Given a csv file with 40 columns with name, address, hometown etc.
I use a bash command in 1 line which:
1. gets the address column and pipes that to
2. grep the first digit and everything that follows
Command:
awk -F ";" '{print $19}' /Users/jb/Desktop/ReorderTempTotal.csv | grep -o "\d.*"... (7 Replies)
The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format:
input
chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18
chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies
LEARN ABOUT DEBIAN
mail::mbox::messageparser::grep
Mail::Mbox::MessageParser::Grep(3pm) User Contributed Perl Documentation Mail::Mbox::MessageParser::Grep(3pm)NAME
Mail::Mbox::MessageParser::Grep - A GNU grep-based mbox folder reader
SYNOPSIS
#!/usr/bin/perl
use Mail::Mbox::MessageParser;
my $filename = 'mail/saved-mail';
my $filehandle = new FileHandle($filename);
my $folder_reader =
new Mail::Mbox::MessageParser( {
'file_name' => $filename,
'file_handle' => $filehandle,
'enable_grep' => 1,
} );
die $folder_reader unless ref $folder_reader;
# Any newlines or such before the start of the first email
my $prologue = $folder_reader->prologue;
print $prologue;
# This is the main loop. It's executed once for each email
while(!$folder_reader->end_of_file());
{
my $email = $folder_reader->read_next_email();
print $email;
}
DESCRIPTION
This module implements a GNU grep-based mbox folder reader. It can only be used when GNU grep is installed on the system. Users must not
instantiate this class directly--use Mail::Mbox::MessageParser instead. The base MessageParser module will automatically manage the use of
grep and non-grep implementations.
METHODS AND FUNCTIONS
The following methods and functions are specific to the Mail::Mbox::MessageParser::Grep package. For additional inherited ones, see the
Mail::Mbox::MessageParser documentation.
$ref = new( { 'file_name' => <mailbox file name>, 'file_handle' => <mailbox file handle> });
<file_name> - The full filename of the mailbox
<file_handle> - An opened file handle for the mailbox
The constructor for the class takes two parameters. The file_name parameter is the filename of the mailbox. The file_handle argument is
the opened file handle to the mailbox.
Returns a reference to a Mail::Mbox::MessageParser object, or a string describing the error.
BUGS
No known bugs.
Contact david@coppit.org for bug reports and suggestions.
AUTHOR
David Coppit <david@coppit.org>.
LICENSE
This software is distributed under the terms of the GPL. See the file "LICENSE" for more information.
HISTORY
This code was originally part of the grepmail distribution. See http://grepmail.sf.net/ for previous versions of grepmail which included
early versions of this code.
SEE ALSO
Mail::Mbox::MessageParser
perl v5.10.1 2009-08-09 Mail::Mbox::MessageParser::Grep(3pm)