LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-22-2007, 08:13 PM   #1
Sparq69
Newbie
 
Registered: Apr 2007
Posts: 0

Rep: Reputation: 0
Linux 4.4 possible awk bug


When I run the following script under Red Hat Linux 4.4:

#!/bin/ksh

if [ $# -ne 1 ]
then
echo "USAGE: $0 filename"
exit 1
else
FileName=$1
fi

cat $FileName | awk ' BEGIN { FS = " "; len = 0; }
{
len = length($0);
printf("%d <%s> %s %s %s\n", len, $0, $3, $2, $1);
printf("<%s> %s %s %s\n", $0, $3, $2, $1);
printf("%s %s %s\n", $3, $2, $1);
printf("<%s>\n", $0);
print "<"$0">";
}'

with the file whose 1 line entry is:

/qed/data/dbgen/Clones M backup.sys.sup.ksh

I get the result as:

M /qed/data/dbgen/Cloness M backup.sys.sup.ksh
M /qed/data/dbgen/Clones backup.sys.sup.ksh
M /qed/data/dbgen/Clones
>/qed/data/dbgen/Clones M backup.sys.sup.ksh
>/qed/data/dbgen/Clones M backup.sys.sup.ksh

Has anyone struck this problem before ???
 
Old 05-13-2007, 03:22 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

This is not an awk bug, but an infile that has CRLF line terminators (probably a dos/windows generated file). Try: file <infile>.

Unix style infile:
Quote:
$ ./s1 infile
43 </qed/data/dbgen/Clones M backup.sys.sup.ksh> backup.sys.sup.ksh M /qed/data/dbgen/Clones
</qed/data/dbgen/Clones M backup.sys.sup.ksh> backup.sys.sup.ksh M /qed/data/dbgen/Clones
backup.sys.sup.ksh M /qed/data/dbgen/Clones
</qed/data/dbgen/Clones M backup.sys.sup.ksh>
</qed/data/dbgen/Clones M backup.sys.sup.ksh>
Dos/Windows style infile:
Quote:
$ ./s1 infile
M /qed/data/dbgen/Cloness M backup.sys.sup.ksh
M /qed/data/dbgen/Clones backup.sys.sup.ksh
M /qed/data/dbgen/Clones
>/qed/data/dbgen/Clones M backup.sys.sup.ksh
>/qed/data/dbgen/Clones M backup.sys.sup.ksh
Your editor may have an option to change the way the file is saved, or use vi to do it (:set ff=unix and save file), or use dos2unix, or tr or.......

Hope this helps.

PS: Sorry for the late reply, only noticed it today

Last edited by druuna; 05-13-2007 at 03:25 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using awk together with linux mail commands Patrick Chuang Linux - Newbie 1 03-15-2007 02:49 AM
awk - check $1 is a linux command or not? kalyanofb Programming 4 02-07-2007 07:51 AM
awk code on linux suchi_s Programming 6 01-13-2005 11:02 PM
same awk script running on linux 7.2 and linux 10 suchi_s Programming 2 11-22-2004 07:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration