Help with UNIX Program


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with UNIX Program
# 1  
Old 02-21-2005
Help with UNIX Program

I am trying to set up a file for someone and they have a program that was built for UNIX. I am guessing that it is running in some sort of emulator since they are on WinXP. It is a database and we are trying to get all of the addresses out of the database. I talked to the tech support for the software, and if I understood them correctly, this is all that can be done.

The data can be outputted to a file (.tmp I believe) and then the information can be saved out to something else. The problem is that it won't be delimited. It will just be one long string of text according to the tech support. Does anyone have any ideas on what I could do to get this in a usable format. The database is about 6000 names, so if you figure that by about 6 pieces of information per name, there is no way that we can go in and physically delimit it.

In case your wondering, the program was written in the early 80's. The new version will output to databbase files, but the upgrade is 100,000 and they aren't willing to do that.

Help.
# 2  
Old 02-21-2005
Well how about a few clues here?? How are we supposed to know where the delimiters go? Post some sample data. And maybe you should tell us what you want to use as a delimiter.
# 3  
Old 02-21-2005
Well, I will know more tomorrow. I was basically asking if something like this is possible. If it is what has been explained to me, the data has a fixed number of characters for each field. It can be comma or tab delimited, but I would prefer tab. Once I actually get the file, I'll post some info.
# 4  
Old 02-25-2005
Ok. Here is a sample of the file I am working with. Turns out, it did format the text, it just isn't the format we need.

What I need is a spreadsheet with the name in one column, the address line in one column and the city, state, zip in another column.

I don't think this is a Unix problem to solve, but more of an excel issue. Maybe a macro to move the information? I also need it to clean out all the blank lines.

The sample is attached to this.
# 5  
Old 02-25-2005
I guess Windows Excel may solve the problem.

But , using unix scripting also we can solve this.
# 6  
Old 02-25-2005
Quote:
Originally Posted by brand1m
Ok. Here is a sample of the file I am working with. Turns out, it did format the text, it just isn't the format we need.

What I need is a spreadsheet with the name in one column, the address line in one column and the city, state, zip in another column.

I don't think this is a Unix problem to solve, but more of an excel issue. Maybe a macro to move the information? I also need it to clean out all the blank lines.

The sample is attached to this.
here's something to start with given your sample file.
Assumptions:
  1. there're 2 columns in your original file
  2. maximum width of the first column is 34 character - this is adjustable
  3. the output fields are separated by "|" - configurable

attached is a the output based on your sample input.

nawk -f brand.awk samplefile.txt

brand.awk:
Code:
BEGIN {
  OFS="|"
  CLMN=2
  WDTH=34
}

#------------------------------------------------------------------------
#
function trim(str)
{
   sub("^[ \t]*", "", str);
   sub("[ \t]*$", "", str);
   return str;
}

#------------------------------------------------------------------------
#
pivot == 3 {
  for(i=1; i <= CLMN; i++)
    for(j=1; j <= pivot; j++) {
      split(arr[j], tmpA, SUBSEP)
      printf("%s%s", tmpA[i], (j < pivot) ? OFS : "\n");
    }
  pivot=0
}

!NF { pivot=0; next}

{
   pivot++
   arr[pivot] = trim(substr($0, 1, WDTH-1)) SUBSEP trim(substr($0, WDTH))
}


Last edited by vgersh99; 03-04-2010 at 01:54 PM..
# 7  
Old 02-28-2005
watch out for typos

pivot == 3 should read pivot = 3
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

C program into UNIX?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Do not know how to implement this into a script in Unix?:confused: 2. Relevant commands, code, scripts,... (8 Replies)
Discussion started by: kinelisch
8 Replies

2. Shell Programming and Scripting

C program into UNIX?

Hello folks! I need help on this one: I have this C known program which I need to save it as "power2.c", and create it as a file in my UNIX environment: /* power2.c -- Print out powers of 2: 1, 2, 4, 8, .. up to 2^N */ #include #define N 16 int main(void) { int n; /* The current... (1 Reply)
Discussion started by: kinelisch
1 Replies

3. Shell Programming and Scripting

Running C program in UNIX

I want to run a C program from my BASH script. Here's some very basic simplified code of my bash script: #!/bin/bash echo "Run C program" ./main.c echo "Ran C program" Here's my main.c: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { ... (3 Replies)
Discussion started by: millsy5
3 Replies

4. Homework & Coursework Questions

Need help with Basic Unix Program

I am a newbie to UNIX. I'm learning UNIX on my own, just trying to get the jerk of how things work in UNIX environment. I am familiar with Windows environment. Can anyone pls write simple 'envprint' programs to : 1) List all the environment Information (using the -l or --l options) 2) ... (1 Reply)
Discussion started by: agup17
1 Replies

5. UNIX for Advanced & Expert Users

C socket program on UNIX

Write a C socket program on UNIX where a TCP client sends/reads a time in decimal 24 hours format to the server and the server echoes the seconds, minutes, and hours in the time. Example: Client sends 18.78 hours and the server displays 18 hours, 46 minutes and 48 seconds. (1 Reply)
Discussion started by: adi_always4u143
1 Replies

6. Programming

compiling c program in unix

if somebody can help me pls. i need the source code for a shell which compiles C or java programs in unix i need a very short and simple one, just the compiling part Respect (2 Replies)
Discussion started by: zlatan005
2 Replies

7. UNIX for Dummies Questions & Answers

UNIX program?

Is there a program out there than runs like the UNIX operating system except in Window mode on Windows XP? Kind of like command prompt cmd.exe? (1 Reply)
Discussion started by: threewingedfury
1 Replies

8. Shell Programming and Scripting

Sorting Program In UNIX

Write a shell program that takes one or any number of file names as input; sorts the lines of each file in ascending order and displays the non blank lines of each sorted file and merge them as one combined sorted file. The program should generate an error message in case any input file does not... (1 Reply)
Discussion started by: kumar_saurabh
1 Replies

9. Programming

getting username from a c program in unix

How to get the user name of the Operating system from a c program. eg:- -rw-r----- 1 gkuser srth1 292 Jul 27 19:28 u1.txt i need to get gkuser as the result? (3 Replies)
Discussion started by: Rajeshsu
3 Replies

10. UNIX for Advanced & Expert Users

looking for a unix C program...help please

Hey Guys, Does anyone have a copy of a c-program which saves/writes files to a sub-directory within the home directory which uses the prototype::: save (char* filename, char* directory_name)::: if at all possible, could share that syntax with me please. Thanx much..... Peace... (3 Replies)
Discussion started by: richardspence2
3 Replies
Login or Register to Ask a Question