File names as array element in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File names as array element in ksh
# 15  
Old 10-14-2014
Hi Chubler_XL, i tried with printf also..its not working.
i tried the below:

Code:
printf "%s %s  \n  \n " "${File[i]}"  "${Member[i]}" >> temp.txt


Last edited by Don Cragun; 10-14-2014 at 05:10 PM.. Reason: Add CODE tags again.
# 16  
Old 10-14-2014
By not working what do you mean is the data all still on one line?

Are you inserting the contents of temp.txt into the email body, or attaching it to the email, I'm assuming your inserting it into the email body.

Check the contents of temp.txt what you want is two spaces in the front of every line in this file that you want starting on a new line. Outlook thinks any line without spaces in the front is part of the previous paragraph and joins it up.

Without code tags around you posted code it's a little hard to tell what use used but it looks like you dont have the 2 spaces at the front on the printf string. You need the printf to be like this:

Code:
printf "  %s %s\n  \n" "${File[i]}" "${Member[i]}" >> temp.txt

This User Gave Thanks to Chubler_XL For This Post:
# 17  
Old 10-14-2014
Hi Chubler_XL, Yes the data still comes in one line. I am attaching the file in the mail, its not body.
below is the code.

Code:
printf "  %s %s\n  \n " "${File[i]}"  "${Member[i]}"  >> temp.txt
cat temp.txt |sort|uniq|sed "1i File Names  \t \t Rejected Member Names\n" > rejmbrs.txt

if i check in Unix, the values are appearing in separate lines as per requirement in rejmbrs.txt.
But when i am attaching the rejmbrs.txt in my email, values are coming in one line.
# 18  
Old 10-14-2014
OK that explains things.

Files in Windows/DOS are different to unix, they need \r\n on the end. Change your printf commands to put \r infront of any \n eg:

Code:
printf "%s %s\r\n" "${File[i]}"  "${Member[i]}"  >> temp.txt

Another option is to use the unix2dos program on your file before attaching:

Code:
unix2dos rejmbrx.txt

This User Gave Thanks to Chubler_XL For This Post:
# 19  
Old 10-15-2014
Hi Chubler_XL, Thanks a ton. You are the Unix Master. I am able to get desired result with your suggestion. Thanks again.Smilie
# 20  
Old 10-15-2014
In CSV:
Code:
a,a.txt\r
b,b.txt\r
c,c.txt\r

Tab separated text is also well supported, without worries about ',' and '"'. But CSV is more robust, allowing you to put multi-line chunks into cells inside ":
Code:
John,Smith,"123 Main ST
Anytown, NJ 08088-121",Democrat\r
Sam,Jones,"234 2nd AVE
Othertown, PA 18088-3456",Republican\r


Last edited by DGPickett; 10-15-2014 at 04:06 PM..
This User Gave Thanks to DGPickett For This Post:
# 21  
Old 10-15-2014
Hi DGPickett, Thanks for your suggestion. I will plan to use csv in stead of txt as enhancement.
Thanks a lot for the help i received.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Unset array element and save to file in Bash

#!/bin/bash X=(2H 4S 10D QC JD 9H 8S) How do I unset the 10D from this array and save it to a file? Please use CODE tags as required by forum rules! (5 Replies)
Discussion started by: cogiz
5 Replies

2. Shell Programming and Scripting

Not able to call an element from an array in ksh

Hi, I have: # Initialize variables #!/usr/bin/ksh FILENM=$1 INDEX=0 # read filename echo "You are working with the Config file: $FILENM" while read line do echo $line data=$line ((INDEX=INDEX+1)) done <"$FILENM" (3 Replies)
Discussion started by: Marc G
3 Replies

3. Shell Programming and Scripting

ksh insert element in array

Hi all, I need help with the following scenario in ksh. If the number of elements contained by arrayA is 11 I need to insert a zero as the element arrayA then print all arrayA elements separated by comma. Appreciate your help. (9 Replies)
Discussion started by: ejianu
9 Replies

4. Emergency UNIX and Linux Support

Assigning zero to element of ksh array.

set -A matched #find referenced files. for i in ${file_names_html} do counter_j=0 for j in ${file_names_minus_index} do match=`cat $i | grep... (1 Reply)
Discussion started by: robin_simple
1 Replies

5. Shell Programming and Scripting

how to assign file names to array variable?

I wish to assign file names with particular extention to array variables. For example if there are 5 files with .dat extention in /home/sam then i have to assign these 5 files to an array. plz help me how to accomplish this. Thanks in advance. (4 Replies)
Discussion started by: siteregsam
4 Replies

6. Shell Programming and Scripting

Problem to initialize ksh array when first element includes hyphen

Hi I'm trying to create an array with variable including hyphen but ksh refuses the first element set -A allArgs set +A allArgs ${allArgs} -all set +A allArgs ${allArgs} -date set +A allArgs ${allArgs} test ./test.ksh: -all: bad option(s) It happens only when first element is like... (4 Replies)
Discussion started by: gdan2000
4 Replies

7. Shell Programming and Scripting

Creating array containing file names

I am wondering how I can save the file names (stored in $file or $fnames) in array which I can access with an index. alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`' set narg = $#argv while ($iarg < $narg) MATH iarg = $iarg + 1 set arg = $argv set opt = ` echo $arg | awk... (1 Reply)
Discussion started by: kristinu
1 Replies

8. Shell Programming and Scripting

Find Directory from array of file names with paths

I have a script that generates a variable with the location of a file and its complete path. What i want to do is to "cd" to the directory where that file is located using the path name of the file. GIS has absolutely failed me. For example when i run my script it generates a variable called... (1 Reply)
Discussion started by: Knome
1 Replies

9. Shell Programming and Scripting

Adding array element in KSH

All, I would like to add the first 10 elements of an array. Here is how I am doing it now (only included first few add ops): #!/usr/bin/ksh ###Grab the array values out of a file### TOTAL=`awk '/time/' /tmp/file.out | awk '{print $4}'` set -A times $TOTAL SUM=$((${times} + times... (3 Replies)
Discussion started by: Shoeless_Mike
3 Replies
Login or Register to Ask a Question