Help/Advise please for converting space delimited string variable to comma delimited with quote
Hi,
I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file.
Example of the SQL will be
For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING.
I then concatenate this variable to DEFAULT_USERS so that IN_STRING="$DEFAULT_USERS $IN_STRING". DEFAULT_USERS contains "SYS SYSTEM DBSNMP RMAN"
The SQL statement will then be as below:
I am converting the IN_STRING variable so it will be 'SYS', 'SYSTEM', 'DBSNMP', 'RMAN', 'AAA', 'BBB', 'CCC' so that the resulting SQL will now be as below:
At the moment, I am doing as below:
It is not the most elegant of awk but it does the trick. I am sure there will awk gurus around here who can make it look better. Feel free to recommend a more 'elegant' awk construct.
While this work, it does not look nice as the string gets longer . For example, the list might spill to 20+ space delimited word.
Can someone please advise if I can use awk to convert the string in such a way that the there will be 5 or 6 values per line? For example, instead of having the following in one line
I would want it to be like
At the moment, I am thinking of looping thru the space delimited list, putting them into array and then going thru a loop and doing the construct. Kinda hoping I will be able to do the same using awk
Any advise will be much appreciated. Thanks in advance.
Following may help you in same.
Output will be as follows.
So this is giving till 5 fields, similarly you could do for 6 or as per your need too by doing little fine tuning to above.
Hi,
Apologies in advance to the moderator if I am posting this the wrong way.
I've searched and found the solution to an old post but as it is a very old post, I don't see an option to update it with additional question.
The question I have is in relation to the following post:
How to... (6 Replies)
Hi,
I am not sure if I've posted this question before.
Anyway, I previously asked about converting lines of text into a comma delimited string. Now I am needing to do the other way around ... :( :o
Can anyone advise how is this possible?
Example as below:
Converting records/lines to... (2 Replies)
Hi,
Is there a one-liner that I can use to change a line of text into a comma delimited string?
For example, convert
user1
user2
user3
user4to
user1,user2,user3,user4Currently using while read x, although got the extra comma at the end that I have to remove manually.
Please... (5 Replies)
Hi all,
I have source file, data looks like
12345 abc def 01 / 001200 C 2000
12345 abc def 01 / 001200 C 2500
12345 abcd def 01 / 001200 C 3500
18945 xyz pqr 01 / 009900 D 4000 5000 2800 9900
Expected ouput... (3 Replies)
Hi How to make tab delimited file to space delimited?
in put file:
ABC kgy
jkh ghj
ash kjl
o/p file:
ABC kgy
jkh ghj
ash kjl
Use code tags, thanks. (1 Reply)
Hi All,
I need a unix script to convert .csv files to .skv files (changing a comma delimited file to a semi colon delimited file). I am a unix newbie and so don't know where to start. The script will be scheduled using cron and needs to convert each .csv file in a particular folder to a .skv... (4 Replies)
I have a file which was pipe delimited, I need to make it tab delimited. I tried with sed but no use
cat file | sed 's/|//t/g'
The above command substituted "/t" not tab in the place of pipe.
Sample file:
abc|123|2012-01-30|2012-04-28|xyz
have to convert to:
abc 123... (6 Replies)
Hi,
I came across a very good script to convert a comma seperated to pipe delimited file in this forum. the script serves most of the requirement but looks like it does not handle embedded double quotes and commas i.e if the input is like
1234, "value","first,second", "LDC5"monitor",... (15 Replies)
Hi all,
I have a file with single white space delimited values, I want to convert them to a tab delimited file.
I tried sed, tr ... but nothing is working.
Thanks,
Rajeevan D (16 Replies)