SUMMARY: shell script help

From: <egold_at_fsa.com>
Date: Tue Apr 20 2004 - 11:40:19 EDT
thanks to all who helped, i recieved over 20 responses in 10 minutes.
Several people mentioned the list is not for this type of question, sorry
about that.
if anyone knows a good shell script list id like to know.

the solution was to to use the IFS variable, which i think tells cat to use
that value as its field seperator, just make to sure to set IFS back to its
original value when done or you can break alot of other stuff.

thanks again!


Well, in the simplest case, you simply need to alter 'IFS'
(Inter-field separator)
It defaults to 'whitespace'.

And I'd recommend 'saving' it because otherwise stuff can break
eg.

OLDIFS=$IFS
IFS="
"
<your script>
IFS=$OLDIFS

You may also wish to consider doing something like (after setting the IFS):
for i in `cat file`
do
  set $i
  KEY=$1
  EDATE=$2
  ...

done



(Although if you're doing that kind if thing, I might suggest having a look
at perl)



ORIGINAL MESSAGE:

Subject:    shell script help


i need help parsing a text file in korn shell on solaris 7. I cant use
perl.
i want to grab each line of an input file then break out the columns
(probably using awk).

here is a sample input file:

TEXT,04/04/04,04/20/04,05/01/03,a description with spaces in it.
JUNK, 4324, 4323432, 324231, another description with spaces in it.
.
.
.

i was using the following code, but then the users started putting spaces
in the last column and broke my script:

for i in `cat inputfile`
do
KEY=`echo $i|awk -F, '{print $1}'`
EDATE=`echo $i|awk -F, '{print $2}'`
MR=`echo $i|awk -F, '{print $3}'`
ENDDATE=`echo $i|awk -F, '{print $4}'`
LASTCOL=`echo $i | awk '{print $5}'`
done

thanx in advance!
E
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
 http://www.sunmanagers.org/mailman/listinfo/sunmanagers



 :._______________
 CONFIDENTIALITY : This  e-mail  and  any attachments are confidential and
 may be privileged. If  you are not a named recipient, please notify the
 sender immediately and do not disclose the contents to another person, use
 it for any purpose or store or copy the information in any medium.
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Tue Apr 20 11:40:13 2004

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:33 EST