AWK question in the KORN shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK question in the KORN shell
# 8  
Old 02-04-2005
Thanks

What can I say...if I could offer you guys a job I would!

I tested it and it works great
# 9  
Old 02-04-2005
A slight variation on the awk theme:


Code:
nawk '
    BEGIN {
        FS = OFS = ";"
    }
    FNR==NR { arr[$1]; next} 
    $1 in arr {
        $2 = 50
    }
    1
' val_id.txt gmrd.txt

# 10  
Old 02-08-2005
Quote:
Originally Posted by Ygor
Using awk...
Code:
awk '
    BEGIN {
        FS = OFS = ";"
        while (getline < "val_id.txt" > 0)
            arr[$1] = 1
    }
    $1 in arr {
        $2 = 50
        $NF =  $NF "<---debug: line changed"
    }
    {print}
' gmrd.txt

Tested...
Code:
235649;50;2563;598<---debug: line changed
291802;00;2563;598
314634;00;235649;598
235649;50;2563;598<---debug: line changed
393692;00;2563;598
411805;00;2563;598
411805;00;2563;598
235649;50;2563;598<---debug: line changed
414037;00;2563;598
etc.

Remove the debug line if this is what you wanted.
Ygor,
In your code you have the line 'while (getline < "val_id.txt" > 0)', what is the '> 0'. Is this redirection or relational operator?

Thanks in advance
# 11  
Old 02-08-2005
I am checking that the return value from getline is greater than zero.

This quote is from: http://www.cs.uu.nl/docs/vakken/st/n..._25.html#SEC28
Quote:
getline returns 1 if it finds a record, and 0 if the end of the file is encountered. If there is some error in getting a record, such as a file that cannot be opened, then getline returns -1.
# 12  
Old 02-09-2005
Thanks Ygor
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

korn shell remove files question

how do you show each filename in a giving directory and delete the specific file in korn script i was thinking using ls rm ? but i cant make it work (0 Replies)
Discussion started by: babuda0059
0 Replies

2. AIX

AIX 4.2 Korn shell and grep question

Ho do I find out the verion of the Kron shell on my client`s system ? There is no one to ask. They are not knowledged enough (hard to believe but yes). Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do... (11 Replies)
Discussion started by: Browser_ice
11 Replies

3. UNIX for Dummies Questions & Answers

Korn shell awk use for updating two files

Hi, I have two text files containing records in following format: file1 format is: name1 age1 nickname1 path1 name2 age2 nickname2 path2 file 1 example is: abcd 13 abcd.13 /home/temp/abcd.13 efgh 15 efgh.15 /home/temp/new/efgh.15 (4 Replies)
Discussion started by: alrinno
4 Replies

4. Shell Programming and Scripting

Could someone give me an example of awk accessing array defined in Korn Shell?

As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies

5. Shell Programming and Scripting

substr() thru awk Korn Shell Script

Hi, I am new stuff to learn substr() function through awk for writing the Korn shell script. Is there a way to copy from XXXX1234.ABCDEF to XXX1234 file names without changing both data files? I appreciate your time to response this email. Thanks, Steve (4 Replies)
Discussion started by: sbryant
4 Replies

6. Shell Programming and Scripting

Korn shell and awk question

I am modifying a Korn shell script in using the Exceed (Solaris 10 environment). My task is to read in a .txt file with dates arranged like this (01-Sep-2006). I am to read each line and take the dates, compare them to a benchmark date and depending on if it is older than the date or the date and... (6 Replies)
Discussion started by: mastachef
6 Replies

7. Shell Programming and Scripting

korn shell question

Hi all, I am trying to tweak my ksh , i am running V: Version M-11/16/88i I have my Backspace and up/down arrows working using the following code in my ~/.profile file. set -o emacs alias __A=$(print '\020' ) alias __B=$(print '\016' ) alias __C=$(print '\006' ) alias __D=$(print... (4 Replies)
Discussion started by: mich_elle
4 Replies

8. Shell Programming and Scripting

Korn Shell Coprocess Performance Question

I am wracking my brains over this. I am trying to use a Korn Shell script to execute an Oracle PL/SQL procedure, using the Oracle command line interface (sqlplus). The script starts sqlplus in a coprocess, and the two processes communicate using a two-way pipe. The bgnice option is off, so both... (8 Replies)
Discussion started by: Mark Puddephat
8 Replies

9. Shell Programming and Scripting

Korn Shell Loop question

I'm needing help with assigning variables inside a while loop of ksh script. I have an input text file and ksh script below and I'm trying to create a script which will read the input file line by line, assign first and second word to variables and process the variables according to the contents. ... (4 Replies)
Discussion started by: stevefox
4 Replies

10. Shell Programming and Scripting

Question about Korn Shell

In Korn Shell, can you use "go to" statements? Would you then put paragraph names with a colon? For example, would you specify "goto para1" and then have the paragraph with the label para1:? I am getting an error message when Idid this. I have my paragraph name 'clsbooks:' and I get... (13 Replies)
Discussion started by: Latha Nair
13 Replies
Login or Register to Ask a Question