Computing.Net > Forums > Unix > Unix Korn shell script to read recs

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Unix Korn shell script to read recs

Reply to Message Icon

Name: Scott H
Date: January 21, 2003 at 07:51:51 Pacific
OS: AIX
CPU/Ram: ?
Comment:

I need to be able to grab the first character in record1 of a file and see if it is the number "1". I then need to grab the first character in record2 of the same file and see if it is the number "9". I can write simple scripts, but this is a new one for me. Is AWK the way to go? (I am also new to AWK) Any help with this would be greatly appreciated. An example of what a portion of the file could look like is shown below.


FILE1

190876465 49494474646 59 595757 {rec1}
90 345667 5753457390 222 {rec2}



Sponsored Link
Ads by Google

Response Number 1
Name: Scott H
Date: January 21, 2003 at 09:45:21 Pacific
Reply:

One thing that I forgot to add is that I only care about the first character in the first two lines/records. I don't need to read the rest of the file if there happens to be more than 2 lines/records in it.

Thanks,
Scott


0

Response Number 2
Name: LANkrypt0
Date: January 21, 2003 at 12:38:41 Pacific
Reply:

So, if I am reading this right, you only need the first character of the first 2 lines correct?

If so
head -2 FILENAME | cut -c 1

Would give you
1
9

If you need to separate them, use either:
| head -1
or
| tail -1
at the end

That should work just fine.


0

Response Number 3
Name: Scott H
Date: January 21, 2003 at 13:27:11 Pacific
Reply:

Thanks LANkrypt0. I feel silly now to see how simple that was.

By the way, it worked great!

Scott


0

Response Number 4
Name: LANkrypt0
Date: January 22, 2003 at 05:13:28 Pacific
Reply:

No problem.

I too have overcomplicated things many times, only to realize later on that some little line of code would have produced the same thing. You learn as you go.

Glad it worked for you.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


need SiS 6215 driver for ... prelinker error



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: Unix Korn shell script to read recs

Korn shell script that reads in in www.computing.net/answers/unix/korn-shell-script-that-reads-in-in/4760.html

Shell script to read a file and pro www.computing.net/answers/unix/shell-script-to-read-a-file-and-pro/4304.html

can an FTP Korn Shell Script be written www.computing.net/answers/unix/can-an-ftp-korn-shell-script-be-written/3569.html