ksh script to anlyze rows in file

Posted on 2006-05-09
Last Modified: 2010-04-20

I have a file with many rows.
Each row contains many words separated by blanks.
I am looking for a script to do the following:

For each line
  VAR1 = the first word (untill the first blank);
  VAR2 = the rest of the line (without the first word);

Question by:peledc
    LVL 4

    Accepted Solution

    do you need it in ksh only, or not ?
    If not here's awk command line  to do it:
    (assume your data file is stam.dat, print is just for sanity check as you've not
    specified what to do next with the variables)

    #awk '{massa[1]=$1; $1=""; massa[2]=$0
    print "First element ",bassa[1]
    print "Rest of the line ", bassa[2] }' stam.dat

    here the array element massa[1] hold the 1st word, and array[2] holds the rest of the line.
    LVL 4

    Expert Comment

    Oops , of course in "print" commands the array name should be 'massa' as well.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
    It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now