[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

ksh script to anlyze rows in file

Hi,

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);
end;

Thanks
0
peledc
Asked:
peledc
  • 2
1 Solution
 
yuriskCommented:
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.
0
 
yuriskCommented:
Oops , of course in "print" commands the array name should be 'massa' as well.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now