Substituting field contents using AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Substituting field contents using AWK
# 8  
Old 10-30-2009
Thanks very much for everybody's replies.

Quote:
Originally Posted by rdcwayx
Code:
awk -F[\ \)] '{print $4, $8,$10, $11, $13,($14~/linger/)?"ChangeBase":"CMBase"}' urfile
z001368 481 start Fri 10:36 ChangeBase
z600620 2478 start Fri 10:36 ChangeBase
z310084 360 start Fri 10:37 ChangeBase
z310338 1074 start Fri 10:38 ChangeBase
z001383 1402 start Fri 10:42 ChangeBase
ChangeAdmin 2155 start Fri 5:30 ChangeBase
u112705 1613 start Fri 10:44 ChangeBase
z600969 1885 start Fri 9:21 CMBase
z602084 2379 start Fri 9:31 CMBase
z310044 1279 start Fri 9:57 CMBase
z602138 903 start Fri 10:02 CMBase
z310084 720 start Fri 10:40 CMBase
u414014 580 start Fri 7:58 CMBase
u112705 1991 start Fri 10:46 CMBase

I couldn't get this one to work... The initial error I got was:
Code:
awk: syntax error near line 1
awk: illegal statement near line 1

I then changed "awk" to "nawk" and got the following fields displayed:
Code:
    phys-agsdev CMBase
    phys-agsdev CMBase
    phys-agsdev CMBase
    phys-agsdev CMBase
    phys-agsdev CMBase
    phys-agsdev CMBase
    phys-agsdev CMBase
    phys-agsdev CMBase
    phys-agsdev CMBase
   ccm_root /dev/tty CMBase
   ccm_root /dev/tty CMBase
   ccm_root /dev/tty CMBase
   ccm_root /dev/pts/29 CMBase
   ccm_root /dev/tty CMBase

Will keep trying on Monday. Thanks
# 9  
Old 11-01-2009
Code:
$ uname -i
SUNW,Sun-Fire-V445
$ awk -F[\ \)] '{print $4, $8,$10, $11, $13,($14~/linger/)?"ChangeBase":"CMBase"}' urfile
awk: syntax error near line 1
awk: illegal statement near line 1

But with nawk, I can run the command.

Code:
$ nawk -F[\ \)] '{print $4, $8,$10, $11, $13,($14~/linger/)?"ChangeBase":"CMBase"}' urfile
z001368 481 start Fri 10:36 ChangeBase
z600620 2478 start Fri 10:36 ChangeBase
z310084 360 start Fri 10:37 ChangeBase
z310338 1074 start Fri 10:38 ChangeBase
z001383 1402 start Fri 10:42 ChangeBase
ChangeAdmin 2155 start Fri 5:30 ChangeBase
u112705 1613 start Fri 10:44 ChangeBase
z600969 1885 start Fri 9:21 CMBase
z602084 2379 start Fri 9:31 CMBase
z310044 1279 start Fri 9:57 CMBase
z602138 903 start Fri 10:02 CMBase
z310084 720 start Fri 10:40 CMBase
u414014 580 start Fri 7:58 CMBase
u112705 1991 start Fri 10:46 CMBase
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies

2. Shell Programming and Scripting

awk to change contents of field based on condition in same file

In the awk below I am trying to copy the entire contents of $6 there may be multiple values seperated by a ;, to $8, if $8 is . (lines 1 and 3 are examples). If that condition $8 is not . (line2 is an example) then that line is skipped and printed as is. The awk does execute but prints the output... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

awk to update value in field of out file using contents of another Ask

In the out.txt below I am trying to use awk to update the contents of $9.. If $9 contains a + or - then $8 of out.txt is used as a key to lookup in $2 of file. When a match ( there will always be one) is found the $3 value of that file is used to update $9 of out.txt separated by a :. So the... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

6. UNIX for Dummies Questions & Answers

substituting variable value in AWK

Hi All, my requirement is as below. I need to replace a value in a particular column with a substitution variable(date value) and modified value of the current column value in the same position. for ex. i have a record like 02;aaaa;bbbbb;cccccc;dddddd;123456789;hhhhh;12hs;asdf ;... (3 Replies)
Discussion started by: ganesh_248
3 Replies

7. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

8. Shell Programming and Scripting

Substituting variable value in AWK /start/,/stop/

Hi all u brilient people on the forum... I am trying to call the variable value in awk command for search pattern /start/,/stop/ but i am nt able to do this .... wat i did is ..i have created two variable YESTERDAY and TODAY and passed the y'day n 2'days dates in it...like this ... (14 Replies)
Discussion started by: whomi
14 Replies

9. Shell Programming and Scripting

Join file contents via common field

I have 2 files with a common parm - Jobname File 1 0507 1202 JOBA 0507 1302 JOBB 0507 1452 JOBC 0507 1552 JOBA 0507 1553 JOBA File2 JOBA abcdefg server4 JOBB defghij server22 JOBC vwxyz12 server55 I would like to take each line from File1 and match the jobname with the jobname... (8 Replies)
Discussion started by: Northerner
8 Replies

10. Shell Programming and Scripting

Remove spaces from first field, and write entire contents into other text file

Hi all, I have searched and found various threads about removing spaces from a field within a text file. Unfortunately, I have not found exactly what I'm looking for, nor am I adept enough to modify what I've found into what I need. I use the following command to remove the first line... (3 Replies)
Discussion started by: carriehoff
3 Replies
Login or Register to Ask a Question