ksh file formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh file formatting
# 1  
Old 02-03-2017
ksh file formatting

Hi.
If I have a txt file in the following format:
Code:
option1=123
option2=abc
option3=321

How do I convert it with KSH into the following format (with the additional prefixed string):
Code:
${filename},::option1=123,option2=abc,option3=321

Many thanks
# 2  
Old 02-03-2017
What have you tried so far?
Is the filename the value or the literal string as shown?

There are various ways to do this, so it would be good to know how you have tried/how you think so that it is supportable in future.



Kind regards,
Robin
# 3  
Old 02-03-2017
Hi. I've tried the following and it seems to work. But maybe there's a better or more efficient way of doing this.

Code:
#!/bin/ksh

typeset filename=dummyfile
typeset NEWLINE="${filename},::"
typeset PARAM_LIST=$(cat a.b)
set -A PLIST $PARAM_LIST

for PARAM in ${PLIST[@]}
do
        NEWLINE="${NEWLINE}"${PARAM}","
done

#drop the last ","
RES=${NEWLINE%?}
print "${RES}"
exit 0

# 4  
Old 02-03-2017
Hi.

The utility paste:
Code:
paste -d, - - - < your-file-name

produces
Code:
option1=123,option2=abc,option3=321

Bes wishes ... cheers, drl
These 2 Users Gave Thanks to drl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting output using awk in ksh

:oi was trying to write a script to format output of a command in ksh which has output as below: so i used : to get which i require at all times. But problem occurs when status part changes. above output i get when status is SU (success).If the status is IN (inactive), output of... (1 Reply)
Discussion started by: pr5439
1 Replies

2. UNIX for Dummies Questions & Answers

Formatting data in a raw file by using another mapping file

Hi All, i have a requirement where i need to format the input RAW file ( which is CSV) by using another mapping file(also CSV file). basically i am getting feed file with dynamic headers by using mapping file (in that target field is mapped with source filed) i have to convert the raw file into... (6 Replies)
Discussion started by: ravi4informatic
6 Replies

3. Shell Programming and Scripting

Formatting file data to another file (control character related)

I have to write a program to read data from files and then format into another file. However, I face a strange problem related to control character that I can't understand and solve. The source file is compose of many lines with such format: T_NAME|P_NAME|P_CODE|DOCUMENT_PATH|REG_DATE ... (3 Replies)
Discussion started by: hk6279
3 Replies

4. Shell Programming and Scripting

Text Formatting using printf[ksh]

Hi All, I am attempting to create a fixed length tilde delimited file using printf. The variables are initialized to fixed length blank spaces a=' ' b=' ' c=' ' d=' ' Sometimes the variable might contain values and sometimes they are... (5 Replies)
Discussion started by: angie1234
5 Replies

5. Shell Programming and Scripting

File Formatting

Hi, Need to delete all the records prior to pattern (INSERT/UPDATE/DELETE). If ' is available, then need to retain it. Input ====================== l_s := ' INSERT INTO TEST' l_P PD := ' UPDATE INTO TEST' l_D := ' DELETE INTO TEST' This is test Input ======================... (1 Reply)
Discussion started by: saurabhbaisakhi
1 Replies

6. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

7. Shell Programming and Scripting

formatting date in ksh

hi all, in ksh, how do i format date so it includes hour and minute ?? i am trying the following command : date +%Om/%Od/%Oy%OH:%M but it displays the hour and minute concatenated with the day/month/year e.g 12/10/0814:08 when i want the output to be 12/10/08 14:08 i tried... (4 Replies)
Discussion started by: cesarNZ
4 Replies

8. Shell Programming and Scripting

Help with formatting of file.

I have a file with following file format - DMCRH|||83000171|||14022008||0430|||8956612.23|J|||3571235|1378452|23468|6894|9234| DMCRH|||83000215|||15092007||0480|||121.33|J|||LineID003|RefNumSP003|RefNumMem003|0004|0003| What i need done is - 1. Cut the firt four digits of the date (eg 1402... (3 Replies)
Discussion started by: divz
3 Replies

9. UNIX for Advanced & Expert Users

formatting textfile inside ksh script using awk not working

I cannot seem to get this text file to format. Its as if the awk statement is being treated as a simple cat command. I manned awk and it was very confusing. I viewed previous posts on this board and I got the same results as with the the awk command statement shown here. Please help. ... (6 Replies)
Discussion started by: tekline
6 Replies

10. UNIX for Dummies Questions & Answers

Help on formatting a number in ksh

I don't know if this is possible. Still fairly new to ksh scripting. Here is what I am wanting to do with my output. change the following From: 1349870987 To: 1,349,870,987 in my output. How do I do this? Thanks, S (1 Reply)
Discussion started by: Speide
1 Replies
Login or Register to Ask a Question