Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URGENT: Need script for reading data from file

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hello!

I am new to AWK and I am having trouble with an AWK script. This is quite urgent so any help is welcome

I have the following file:
Project name Creation date
------------ -------------------
angnew 01132000 15:00:00 ANGLIA/ORACLE
brent 30062000 12:00:00 NNS/ORACLE
colt 08281998 12:53:55 COLT_41/ORACLE
colt98 10221998 15:02:17 COLT98/ORACLE
eva 09122001 14:43:41 NNS/ORACLE lgc_master
fl2d 09081999 09:34:41 FLOUNDER981/ORACLE lgc_master
fl2d_tut 11301999 16:29:16 FLOUNDER981/ORACLE fl2d_mast
flndr3d 04101997 11:20:14 FLOUNDER981/ORACLE
flndr3dn 07071999 09:54:17 FLOUNDER981/ORACLE
frisco 04042000 10:33:20 RG_FRISCO/ORACLE
jamtest 10122001 10:03:35 FLOUNDER981/ORACLE
paradise 06241999 09:13:38 FLOUNDER981/ORACLE
pmseis 09082001 11:56:42 PRIYA_TEST/ORACLE
poslog3d 03032000 12:54:39 POSLOGS/ORACLE
priya3d 08082001 15:37:31 PRIYA_TEST/ORACLE
quad22 07281997 23:09:54 CNSOW/ORACLE

I would like to extract all the project names (e.g., FLOUNDER981 without /ORACLE and do not select it twice), store the name in an array.
I need this as an input for another program. Can I do that within the AWK script as well?

Thanks a lot!

Fabien
 
You could use

awk '{print $3}' < &quot;input file name&quot; |cut -d\/ -f1|sort -u > &quot;output file name&quot;

It depends on how your other program is set up to receive data but in theory you could pass the results to another program you would use

awk '{print $3}' < &quot;input file name&quot; |cut -d\/ -f1|sort -u |&quot;other program&quot; name

Let me know if you need any further help. SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
Thanks a lot SOL!

Actually it's $4 that I need I tested it and it looks fine except that the first line is a blank, how can I get rid of it?

Thanks again!

Fab
 
Sorry counting problems! I assume that the first line of your input file isn't blank? Is the output line actually blank (i.e. padded with blanks ) or null ( i.e. empty line )? SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
Yes the first line will be always blank.

In addition, the script the so far like this

awk '{print $4}' < &quot;input file name&quot; |cut -d\/ -f1|sort -u |&quot;other program&quot; name > output

How can I write the input to &quot;other program&quot; i.e., in the output file in between calls to &quot;other program&quot;

i.e in output file there will be

ANGLIA
output from other program

RG_FRISCO
output from other program
.
.
.


 
Okay to remove the blank line use

awk '{ if (NR>1){print $4}}' < &quot;input file name&quot; |cut -d\/ -f1|sort -u |&quot;other program&quot; name > output

What is the other program you need to pass the data to and how does it expect it's output? If it's a script, could you send a copy through? SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
Thanks this worked to skip the comment line but I still had to add a condition like if ($4!=&quot;&quot;) to get rid of the blank.

Giving you the other script won't help you much it's a C
program.
It only requires a name as input.

The awk script you gave me helped extracting the info from the file now I need to pipe this info into the C program
and write the output of the C program to a file with a specific name

The output of the first script is something like
ANGLIA
TOTO
TUTU
TITI

I want to pipe this into the C program and output the result into ANGLIA.dat file. How can I do this?

Sorry to be a pain!

Thanks,

Fabien
 
Okay I need to understand the syntax that would be entered on the command line for running the C program. Is it something like?
&quot;C program name&quot; &quot;data to be input&quot; >> anglia.dat
SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
it is &quot;C program name&quot; &quot;name from previous AWK script, i.e. ANGLIA..&quot; > &quot;name from previous script&quot;.dat

 
Okay this should do what you want.

awk '{ if (NR>1){print $4}}' < tempsb2.txt |cut -d\/ -f1|
sort -u |awk '{if ($0!=&quot;&quot;){print $0}}'|
awk '{VAR=$0;system(&quot;****** &quot;VAR&quot; > &quot;VAR&quot;.dat&quot;)}'

This should all be one line. Enter your C program name where the ****** are.Let me know if you have any problems. SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
Thanks SOL but it does not work. It seems that system does not work because I have the right values for VAR (I inserted a print VAR before system) but nothing is written to disk. How can I tell if the program worked?

Thanks,

Fabien
 
It may depend on what operating system and awk you are using, although I haven't come across a version that differs on it's use of system(cmd) within AWK. I tested the script with a sample program and it worked fine. What operating system are you on? Could you also send a copy of your reproduction of the code? SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
Also you may need to specify the absolute pathname to the C program, if it isn't in the current directory. SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
SOL,

I am running on a Sun Solaris 8, I have change the second awk to nawk and it worked fine! Do you known why?


Thanks again for your help

Fab
 
You're welcome. I don't know why the change worked as I'm on HP-UX, I don't have nawk, just awk. SOL
Yeah people they won't understand,
Girlfriends they don't understand,
In spaceships they don't even understand,
and me I aint ever gonna understand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top