Computing.Net > Forums > Unix > Array in a Shell Script

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.

Array in a Shell Script

Reply to Message Icon

Name: Nish
Date: September 10, 2002 at 01:28:42 Pacific
OS: Solaris
CPU/Ram: 254
Comment:

I have a file with same length lines (300 chars each) and need to check one digit (if !=0) and process it(to append to a seperate file). I used cut command to extract required columns and paste them in another file.But I cannot compare the 49th caracter (a digit) without buffering a line. How do I define an array in ksh?
Appreciate If you could suggest any other alternative method.



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: September 10, 2002 at 06:32:50 Pacific
Reply:

awk is good for that, and you do not need to send the original file through the cut process first. Following code will select the lines that do not have a zero in column 49 and will append portions of that line to an output file:

awk 'substr($0,49,1)!=0 {\
print substr($0,1,10) substr($0,55,7)
}' infile >> outfile

If the fields of infile are clearly delimited with something (white space, commas, whatever), then the awk code can refer to those fields as $1, $2, etc instead of using substring function.


0

Response Number 2
Name: Nish
Date: September 10, 2002 at 22:43:12 Pacific
Reply:

Appreciate Your Help.
awk Solved my Problem !!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Lost my windows 2000 pass... Root password



Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Array in a Shell Script

Auto say y or n in a shell script www.computing.net/answers/unix/auto-say-y-or-n-in-a-shell-script/4059.html

Exit from sqlplus in a shell script www.computing.net/answers/unix/exit-from-sqlplus-in-a-shell-script/8244.html

Parameter file for a shell script www.computing.net/answers/unix/parameter-file-for-a-shell-script/6026.html