[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

identify strings in KSH

On Solaris and ksh

I have a file with around 1000 rows in the following format:
-----------------------------------------------
TAB1  "sd sd gfg etgtr4gfr d"
TAB45  
TABHG3              "dfd f as4e4f5gt"
TABG
TAB4   "al ffd rg r5 45 fr"
-----------------------------------------------

I need to identify the first word and if exists, the second one and store them in local variables.

Can any one help here?

Thanks
0
peledc
Asked:
peledc
1 Solution
 
yuzhCommented:
Here's a script example:

#!/bin/ksh

INFILE=/path-to/inputfile
WORD1=$1
WORD2=$2
if  grep -w $WORD1 $INFILE ; then
    # try to find another match
     if  grep -w $WORD2 $INFILE ; then
         VAR1=$WORD1
         VAR2=$WORD2
      else
          echo "$WORD2  does not exist in file $INFILE "
      fi
else
   echo "$WORD1  does not exist in file $INFILE " 
fi

# do something else
exit
#End of script
0
 
TintinCommented:
ksh is going to be very slow for this task.  Please explain what you are trying to acheive.
0
 
peledcAuthor Commented:
My mistake.

A file contains many rows.
for each row I need to separate the first word from the rest of the line.
Thats it.

Sorry for the mixup.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ozoCommented:
Is the first word not already separate from the rest of the line?
If not, what makes it the first word?
0
 
peledcAuthor Commented:
separated by blanks
0
 
ozoCommented:
If the first word is already separate from the rest of the line, why do you need to separate the first word from the rest of the line.?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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