Computing.Net > Forums > Linux > awk and substr

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk and substr

Reply to Message Icon

Name: yacob
Date: March 14, 2008 at 13:42:22 Pacific
OS: Linux
CPU/Ram: 2Gb
Comment:


Dear all

I have an awk script as below but it just prints only to the last file when I wanted t o print all which satisfies the the "if" conditions. I do not know why but it it only print the last file in the out put file when there are many in my files that satisfy the if condition. Can u help ? See below

#!/bin/sh
for i in GX* ;
do
echo $i | awk '{ if ( substr($1, 28, 3) > 100 && substr($1, 36, 3) < 300 ) print "jun_"substr($1, 24, 4)}' > out
done

The output "out" only contain the last file that satisfy the condition but it should contain all the file that satisfy the if condition, and I know there are a lot of them. Why is that ? How ever if I directed to the screen all files that satisfy get printed in the screen.

Regards
Yacob



Sponsored Link
Ads by Google

Response Number 1
Name: yacob
Date: March 14, 2008 at 13:53:48 Pacific
Reply:

Dear All

I have just got the answer, sorry
I should have put >>


0

Response Number 2
Name: ernie
Date: March 15, 2008 at 06:35:26 Pacific
Reply:

That is the answer.

> redirects a command's output to the named file. If the named file already exists, it is overwritten. If the named file does not exist, it is created.

>> also redirects a command's output to the named file. If the named file exists, output is appended to the file. If the named file does not exist, it is created.

This explanation is intended for users who may be unfamiliar with command redirection.

HTH,

Ernie Registered Linux User 247790
ICQ 41060744


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Linux Forum Home


Sponsored links

Ads by Google


Results for: awk and substr

shell script help www.computing.net/answers/linux/shell-script-help/15420.html

Editing www.computing.net/answers/linux/editing/8920.html

suppress output from a command to STDOUT www.computing.net/answers/linux/suppress-output-from-a-command-to-stdout/9778.html