ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

QSHELL comma

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QSHELL comma

    I have a little QSHELL script that reads a csv file, does some formatting on each word and puts it back into a csv file... sort of.

    When I try to append the $WORD to the current line it works fine except when I use a comma. For example this works

    Code:
    ln=${ln}'comma'${WORD}
    This does not output ,
    Code:
    ln=${ln}','${WORD}
    I am guessing it has something to do with the csv file I am reading since this works fine
    Code:
    r=dog
    s=food
    r=$r,$s
    
    echo $r
    Here is the script if that helps
    Code:
    IFS=,
    ###REMOVE EXISTING FILE
    echo '' >> $2
    
    while read LINE
    do
    
    ln=""
    
    
    for WORD in $LINE
    do
        mb=0 ##FORMAT IND
    	db=0 ##FORMAT IND
    	
    	case $WORD in
    	*\/*) 
    
    	    ##GET MONTH
    		m=${WORD:0:2}
    		##FORMAT MONTH IF NEEDED
    		case $m  
    		in *\/*)
    			m=0${m:0:1}
    			mb=1
    		;;esac
    		##GET DAY
    		if [[ $mb -eq 1 ]]
    		then 
    			d=${WORD:2:2}
    		else
    			d=${WORD:3:2}
    		fi
    		##FORMAT DAY IF NEEDED
    		case $d in 
    		*\/*)
    		  d=0${d:0:1}
    		  db=1
    		 ;;esac
    		##GET FULL DATE BASED ON OFFSETS
    		if [[ $mb -eq 1 -a $db -eq 1 ]]
    		then
    			WORD=${m}"/"${d}"/"${WORD:4}
    		elif [[ $mb -eq 0 -a $db -eq 0 ]]
    		then
    			WORD=${m}"/"${d}"/"${WORD:6}
    		else
    			WORD=${m}"/"${d}"/"${WORD:5}
    		fi
    				
    	;;esac
    	
    	if [ -n "$ln" ]
    	then 
    		ln=${ln}'a,'${WORD}
    	else
    		ln="$WORD"
    	fi
    done
    
    echo $ln'\n' >> $2
    done < $1 ###$1 is input file

  • #2
    Re: QSHELL comma

    Opps I guess the IFS needs to be reset before it outputs to the file and than reset to ,

    Code:
    IFS=^
    echo $ln'\n' >> $2
    IFS=,

    Comment


    • #3
      Re: QSHELL comma

      Nice when you answer your own questions..

      Jamie
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment

      Working...
      X