Shell scripts for record Re format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripts for record Re format
# 1  
Old 09-25-2009
Shell scripts for record Re format

I have few files from windows which are tab delimited or ‘|' delimited files.
I need to convert these files without any delimiter ( so in a way it would become variable length with no delimiter )
Can someone help me with the command in bourne shell scripts., ( I am trying with awk )
Thanks In Advance,
# 2  
Old 09-25-2009
Quote:
Originally Posted by Shanks
[( I am trying with awk )
How do your code looks like?

Regards
# 3  
Old 09-25-2009
Honestly , so far
I had been trying with command line Vi , Sed commands.
trying to put the code together now , I had from the forum , so looking for <tr> and <expand> too
# 4  
Old 09-25-2009
Quote:
Originally Posted by Shanks
I have few files from windows which are tab delimited or ‘|' delimited files.
I need to convert these files without any delimiter ( so in a way it would become variable length with no delimiter )
Can someone help me with the command in bourne shell scripts., ( I am trying with awk )

To remove the pipe symbols:

Code:
tr -d '|' < FILE

To replace the pipe symbols with spaces:

Code:
tr '|' ' ' < FILE

To remove the tabs:

Code:
tr -d '\t' < FILE

To replace the tabs with spaces:

Code:
tr '\t' ' ' < FILE

# 5  
Old 09-25-2009
Thanks for the Tips,

For a normal Situation , for e-g
Normal Data file
Field1<tab>Field2<tab>Field3 ,
Field1<tab>Field2<tab>Field3 ,
All the tabs will be removed and become a variable length data , after using tr -d '\t' < FILE
Field1Field2Field3 ,
Field1Field2Field3 ,
For a comma separated data file , the possibility of the comma appearing in the actual field value is higher for e-g

Field1,Field2,Field3
Field1,ABC,corporation,Field3

We can’t use <tr> to remove all the comma , Is there a way to distinguish the fields delimiters and the field value.

Please advice.
# 6  
Old 09-25-2009
It could be possible only if there are some fixed conditions.
For eg. take your data.
Code:
Field1,Field2,Field3
Field1,ABC,corporation,Field3

1. If you think Filed1 and field3 will never have cammas in them, then logically you need to remove the first and the last commas (or say last 5 commas). And this can be done.
Code:
Field1,ABC,corporation,Field3,Field4,Field5,Field6,Field7

2. Or you can avoid those that come with in quotes (double " or single ' or some other character).
Like
Code:
Field1,"ABC,corporation",Field3

Without any condition, how will you yourself decide which should not/be removed?
# 7  
Old 09-28-2009
Sure , I agree. Let me check all the possible option.
Thanks for the reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format your scripts with shfmt

I've been working on a tool to format (style) shell programs, much like gofmt for Go. After much testing and personal use, I'm throwing it out there to see if it's useful to anyone else. GitHub - mvdan/sh: A shell parser and formatter in Go You'll need golang to build and install it. If this... (11 Replies)
Discussion started by: mvdan
11 Replies

2. Shell Programming and Scripting

Need code for updating second record to first record in shell scripting

Hi,, I have requirement that i need to get DISTINCT values from a table and if there are two records i need to update it to one record and then need to submit INSERT statements by using the updated value as a parameter. Here is the example follows.. SELECT DISTINCT ID FROM OFFER_GROUP WHERE... (1 Reply)
Discussion started by: Samah
1 Replies

3. UNIX for Dummies Questions & Answers

Help! needed to displaying an output in record format

Hi Friends, Am new to Unix world and this is my first post in this forum. I was stuck in displaying the content. while displaying the content the below points to be taken care 1 ) The header format is repeating 2) To display the value in table format... (2 Replies)
Discussion started by: rocky2013
2 Replies

4. Shell Programming and Scripting

counting particular record format in a file using AWK

I am trying to count records of particular format from a file and assign it to a variable. I tried below command br_count=wc -l "inputfile.dat"| awk -F"|" '{if (NF != "14") print }' but I amnot able to get it done. Please share me some idea how to get it done. Thanks in advance (7 Replies)
Discussion started by: siteregsam
7 Replies

5. UNIX for Dummies Questions & Answers

converting scripts from dos 2 unix format

Hi, I am new to shell scripting and exploring it , I have developed few sample shell script but I have developed them on windows xp notepad and then saving them on folder and then testing them on cywgin and running perfectly...but these scripts are in dos format and I want to convert them in unix... (1 Reply)
Discussion started by: rahul125
1 Replies

6. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

7. Shell Programming and Scripting

Script to perform record format checks

Hi All, I have a requirement to perform the following checks. Input file is a "|" delimited file and looks like this. A|c1|c2|c3|.... B|G1|G2|G3.... C|H1|H2|H3... A|c4|c5|c6|.... B|G4|G5|G6.... C|H4|H5|H6... Now the check is to see if all the "A" records have a corresponding B... (7 Replies)
Discussion started by: gsjdrr
7 Replies

8. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

9. Shell Programming and Scripting

Want to Convert Scripts in Linux format

I have scripts which I want to convert in Linux format. Note these scripts are in txt format.But I want to convert them in Linux, as DBA's will be using this script. Any command or utility which converts tht files in proper Linux format. Thanks in Adavce. Kunal (1 Reply)
Discussion started by: niceboykunal123
1 Replies

10. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies
Login or Register to Ask a Question