Efficient way of Awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Efficient way of Awk
# 1  
Old 07-11-2006
Efficient way of Awk

Hi,
Can someone let me know if the below AWK can be made much simpler / efficient ?

I have 200 fields, I need to substr only the last fields.
So i'm printing awk -F~ 'print {$1, $2, $3....................................$196,$197 , susbstr($198,1,3999), substr($199,1,3999)..}'

Is there a way we can rewritten ??

Thnx
# 2  
Old 07-11-2006
By efficient I think you mean readable
Code:
awk -F~ '{ for(i=1;i<198;i++){
                printf("%s ", $i);
              }
              for(i=198;i<NF;i++){
                printf("%s ", substr($i,1,3999);
              }
              printf("%s\n", $NF);
          }' someinputfile

Most awks cannot read lines longer 2048 bytes, so I don't get the substr($199,1,3999)
part....

edit per vgersh99

Last edited by jim mcnamara; 07-11-2006 at 11:58 AM..
# 3  
Old 07-11-2006
braindrain,
how many of 'last' fields do you need to operate on?

jim,
NR != NF
# 4  
Old 07-11-2006
Vgersh,
I have last 3 fields to be operated upon.

Also, If AWK / other stream editors cannot operate on string of 4000, is there an alternative that we can use. I have a continous string of 4500, due to limitation in oracle which can stroe 4000, I would like to trim it forehond.

there were some discussion in this forum not very decisive, so I had open a thread, sorry.

Last edited by braindrain; 07-11-2006 at 01:34 PM..
# 5  
Old 07-11-2006
Code:
nawk -F~ -v OFS='~' '{
              for(i=(NF-3);i<=NF;i++){
                $i = substr($i,1,3999);
    
              $1=$1; print
          }' someinputfile

if 'nawk' does break on your records and if you're on Sun/Solaris try '/usr/xpg4/bin/awk' OR if you have 'gawk' installed on your system - try it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Efficient awk way to add numbers in line fields

data.now: blah1,dah,blaha,sweet,games.log,5297484456,nagios-toin,529748456,on__host=93 SERVICE__ALERT_=51 Warning___The__results__of__service=16 Warning___on__host=92 Auto_save__of__retention__data__completed=1 Warning___Return=68 PASSIVE__SERVICE__CHECK_=53 ,1026--1313,1... (12 Replies)
Discussion started by: SkySmart
12 Replies

2. Shell Programming and Scripting

Combining awk command to make it more efficient

VARIABLE="jhovan 5259 5241 0 20:11 ? 00:00:00 /proc/self/exe --type=gpu-process --channel=5182.0.1597089149 --supports-dual-gpus=false --gpu-driver-bug-workarounds=2,45,57 --disable-accelerated-video-decode --gpu-vendor-id=0x80ee --gpu-device-id=0xbeef --gpu-driver-vendor... (3 Replies)
Discussion started by: SkySmart
3 Replies

3. Shell Programming and Scripting

Efficient way to search array in text file by awk

I have one array SPLNO with approx 10k numbers.Now i want to search the subscriber number from MDN.TXT file (containing approx 1.5 lac record)from the array.if subscriber number found in array it will perform below operation.my issue is that it's taking more time because for one number it's search... (6 Replies)
Discussion started by: siramitsharma
6 Replies

4. Shell Programming and Scripting

More efficient awk parser

I have an awk parser, that works great if the data is NC_0000 (four digits), but if it is not that then the data is parsed. I'm not sure the most efficient way to obtain the desired output. Thank you :). Code: awk 'FNR > 1 && match($0, /NC_0000(*)\..*g\.(+)(.)>(.)/, a){ print a, a, a, a, a }'... (14 Replies)
Discussion started by: cmccabe
14 Replies

5. Emergency UNIX and Linux Support

Help to make awk script more efficient for large files

Hello, Error awk: Internal software error in the tostring function on TS1101?05044400?.0085498227?0?.0011041461?.0034752266?.00397045?0?0?0?0?0?0?11/02/10?09/23/10???10?no??0??no?sct_det3_10_20110516_143936.txt What it is It is a unix shell script that contains an awk program as well as... (4 Replies)
Discussion started by: script_op2a
4 Replies

6. Shell Programming and Scripting

efficient search

Hi, i have 2 files each with 200K lines. Each line contains a number. Now, i need to get the list of numbers existing in one fine and NOT in other file. I'm doing this by reading each number from 1 file and grepping on other file. But this taking LOT of time. Is there any efficient way of doing... (14 Replies)
Discussion started by: prvnrk
14 Replies

7. Shell Programming and Scripting

help on most efficient search

Hello, We have a directory with 15 sub-directories where each sub-directory contains 1.5 to 2 lakhs of files in it. Daily, around 300-500 files will be uploaded to each sub-directory. Now, i need to get the list of files received today in most efficient way. I tried using "find with newer... (16 Replies)
Discussion started by: prvnrk
16 Replies

8. Shell Programming and Scripting

Can you suggest a more efficient way for this?

Hi I have the following at the end of a service shutdown script used in part of an active-passive failover setup: ### # Shutdown all primary Network Interfaces # associated with failover ### # get interface names based on IP's # and shut them down to simulate loss of # heartbeatd ... (1 Reply)
Discussion started by: mikie
1 Replies

9. Shell Programming and Scripting

Is there a more efficient way?

I'm using korn shell to connect to oracle, retrieve certain values, put them in a list, and iterate through them. While this method works, I can't help but think there is an easier method. If you know of one, please suggest a shorter, more efficient method. ############### FUNCTIONS ... (6 Replies)
Discussion started by: SelectSplat
6 Replies

10. UNIX for Advanced & Expert Users

Efficient Dispatching

Does anyone know what's new with Efficient dispatching in the Solaris 2.8 release (vs Solaris 2.6) release? Specifically, does anyone know of a good website to get detailed information on thread dispatching using efficient dispatching in solaris 2.8? Thank you. (1 Reply)
Discussion started by: uchachra
1 Replies
Login or Register to Ask a Question