Shell script to separte columns...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to separte columns...
# 1  
Old 07-09-2007
Shell script to separte columns...

Hi all,
I have a data file and need to load the data into tables in a database. The problem is I cannot use a while loop with each line as the data is free text and has all kinds of weird characters including carriage returns and new line characters.
Each column is separated by ~^~ and a new line by ^~EOR~^
so an example would be

ID NAME DESCRIPTION

123~^~SAM~^~HELLO^~EOR~^
~^~~^~HELLO^~EOR~^
456~^~~^~^~EOR~^

How do I separate different columns from above.
Thanks in advance...
# 2  
Old 07-09-2007
See if this helps you:
Code:
sed -e 's/^M/ /g' -e 's/~^~/|/g' -e 's/\^~EOR~\^/|/' input_file

Where '^M' is ctl-M (entered as ctl-V+ctl-M)
# 3  
Old 07-09-2007
Check out talend open studio (Free & Open Source) which makes this kind of transform trivial. It's all point and click and can optionally produce Java or Perl code to do the trick in future.

-c
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Matches columns from two different files in shell script

Hi friends, i want to compare first columns from two different files ,if equal print the file2's second column else print the zero.Please help me... file1: a b c d efile2: a 1 c 20 e 30 desired output: 1 0 20 0 30 Please use CODE tags as required by forum rules! Please post in... (1 Reply)
Discussion started by: bhaskar illa
1 Replies

2. UNIX for Beginners Questions & Answers

Format columns and heads using shell script

My program output text file data in columns format. My problem is the column headers do not align with the data and if filesystem and Mounted On columns pathname are too long the text will not wrap. Is there any function in Unix that I can use in my code that will align the data for each... (11 Replies)
Discussion started by: dellanicholson
11 Replies

3. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

4. Shell Programming and Scripting

Help in adding text before columns in shell script

Hello, Can someone please help in below requirement. My requirement is to add date before to first column,some text before 1st,2nd coulmns and insert a new column in between 2 and 3 columns. input file. aa 123 dddd aa 667 kdkdk ddj 738 kkkk aa 123 dddd aa 667 ... (5 Replies)
Discussion started by: Cva2568
5 Replies

5. Shell Programming and Scripting

Shell script to convert rows to columns

Hi I have a file having the values like below ---------------------------- .set A col1=”ABC” col2=34 col3=”DEF” col4=”LMN” col5=25 .set A .set B col1=55 col3=”XYZ” col4=”PQR” col5=66 .set B .set C col2=”NNN” (1 Reply)
Discussion started by: Suneel Mekala
1 Replies

6. Shell Programming and Scripting

how to arrange datas in columns in shell script.

Hello All, I have datas in the below format. Mark 45 Steve 60 Johnson 79 Elizabeth 90 My requirement is to arrange the data in the order as shown in the attachment. My OS is Solaris. ... (6 Replies)
Discussion started by: vashece
6 Replies

7. Shell Programming and Scripting

Converting rows to columns using shell script

I have a script which converts rows to columns. file_name=$1 mailid=$2 #CREATE BACKUP OF ORIGINAL FILE #cp ${file_name}.xlsx ${file_name}_temp.xlsx #tr '\t' '|' < ${file_name}_temp.xlsx > ${file_name}_temp.csv #rm ${file_name}_temp.xlsx pivot_row=`head -1 ${file_name}` sed 1d... (3 Replies)
Discussion started by: andy538
3 Replies

8. Shell Programming and Scripting

Appending columns of two files using shell script

Hi, I am using ksh, I want to read one csv file and append the columns of another file with new column. My input file: col1,col2 --------- siri,886 satya,890 priya,850 Another file with the below date:(test.csv) col3 ----- 321 333 442 (1 Reply)
Discussion started by: siri_886
1 Replies

9. Shell Programming and Scripting

edit columns in unix shell script

i have a file which if you will open as xls will yield something like this: Column1 Column2 Column3 ABC CDE EFG GHI IJK KLM MNO OPQ QRS what i want to need is to have this kind of results: Column1 ABC CDE EFG GHI IJK ... (10 Replies)
Discussion started by: kingpeejay
10 Replies

10. Shell Programming and Scripting

shell script required to convert rows to columns

Hi Friends, I have a log file as below siteid = HYD spc = 100 rset = RS_D_M siteid = DEL spc = 200 rset = RS_K_L siteid = DEL2 spc = 210 rset = RS_D_M Now I need a output like column wise as below. siteid SPC rset HYD 100 RS_D_M (2 Replies)
Discussion started by: suresh3566
2 Replies
Login or Register to Ask a Question