FIELDWIDTHS problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FIELDWIDTHS problem
# 1  
Old 10-12-2012
FIELDWIDTHS problem

Hello;
i have a file contains records such as below, i want to AWK read pre-defined fixed column width and print desired output. so i wrote this command:
input:
Code:
Event  9477887 Western Iran 
   Date       Time        Err   RMS Latitude Longitude  Smaj  Smin  Az Depth   Err Ndef Nsta Gap  mdist  Mdist Qual   Author      OrigID 
2006/01/05 13:01:03.00   0.62 0.200  35.6620   48.9170   1.6   2.2  -1  14.1   5.8         6  99                      THR        8215551 
2006/01/05 13:01:03.00        0.190  35.6620   48.9170f                 14.1          9    6  99   1.40   3.55     uk CSEM       8887307 
2006/01/05 13:01:04.38   0.34 1.220  35.6253   48.8500 4.434 4.012  47  10.0f        41   37  89   0.91   6.77 m i    ISCJB      9946421 
2006/01/05 13:01:04.50   0.94 0.300  35.2540   44.5910  40.3 119.6  -1  33.0f              6 357                      KISR       8534710 
2006/01/05 13:01:05.80        0.200  35.6670   48.7830                   4.8              25                          TEH        8154540 
2006/01/05 13:01:05.36   0.33 1.336  35.6370   48.8597 4.277 4.098 109  10.0f        41   37  89   0.90   6.78 m i    ISC        8932084

command:
Code:
 awk 'BEGIN {FIELDWIDTHS="11 11 2 6 6 9 9 1 6 6 4 5 2 5 5 5 4 7 7 2 2 3 10 8"} $23=="ISC" {print $0}' input > output

to print each lines contains "ISC" in column number 23. but the out put is nothing to show!
# 2  
Old 10-12-2012
FIELDWIDTHS is a GNU extension.

What's your system?
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 10-12-2012
Fedora 17 i386
# 4  
Old 10-13-2012
You could use "cut" to extract a certain range of characters from each line:

Code:
cut -cnn-mm /path/to/infile

will extract columns nn to mm as string and display this at <stdout>. You can even combine several such clauses. For instance:

Code:
cut -c 1-3,5-10,25-30

will cut three parts out of each line and display these separated by blanks.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 10-13-2012
Or, since you know the field widths and want to print the entire lines:
Code:
awk 'substr($0,119,4)=="ISC "' input >output

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Router problem or ISP problem ?

Hi everyone, I am experiencing discontinuity of Internet service, this started 1 month ago. Everything worked very well for 1 year of intensive use, but now, I have problems reaching my gateway. The gateway is not my router but a node belonging to my ISP and I share the same public IP with... (3 Replies)
Discussion started by: remic
3 Replies

2. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

3. Shell Programming and Scripting

fieldwidths, printf and calculations with variables

Hello guys, I have a problem concerning the formatting when performing calculations with variables passed to awk and using fieldwidth definitions and printf. I have the following code: awk 'BEGIN{ FIELDWIDTHS = "5 3 7 5 8 8 8" }{if ($7 != "") printf"%s%-s%s%s%s%s%s\n",$1,$2,$3,$4,$5,$6,$7;... (2 Replies)
Discussion started by: origamisven
2 Replies

4. IP Networking

Problem with forwarding emails (SPF problem)

Hi, This is rather a question from a "user" than from a sys admin, but I think this forum is apropriate for the question. I have an adress with automatic email forwarding and for some senders (two hietherto), emails are bouncing. This has really created a lot of problems those two time so I... (0 Replies)
Discussion started by: carwe
0 Replies

5. Red Hat

Mail Problem. Maybe, it is a DNS Problem!

Hi, i've a redhat linux 9 upadated by redhat from 7 version to 9 version. A couple of days ago i was a problem with my mail, in other words i'm not able to get any email nor to send any email. I've a proxy configuration and i tried to set iptables in order to verify the port. The 110,255 and 995... (1 Reply)
Discussion started by: pintalgi
1 Replies

6. AIX

user login problem & Files listing problem.

1) when user login to the server the session got colosed. How will resolve? 2) While firing the command ls -l we are not able to see the any files in the director. but over all view the file system using the command df -g it is showing 91% used. what will be the problem? Thanks in advance. (1 Reply)
Discussion started by: pernasivam
1 Replies

7. Shell Programming and Scripting

awk{FIELDWIDTHS} replacing blanks with null

Hi, I am having a file and grabbed the contents of the field according to field widths. The command i used is: awk 'BEGIN{FIELDWIDTHS="10 25 20 14 6 10"}{print$4,$5,$6}' newtext.text >test1.txt i got the output for example: val1 val2 val3 <blank> ... (3 Replies)
Discussion started by: rish_max
3 Replies

8. Shell Programming and Scripting

ssh script problem problem

Hi Please help me with the following problem with my script. The following block of code is not repeating in the while loop and exiting after searching for first message. input_file ========== host001-01 host001-02 2008-07-23 13:02:04,651 ConnectionFactory - Setting session state... (2 Replies)
Discussion started by: pcjandyala
2 Replies

9. Shell Programming and Scripting

problem with dd command or maybe AFS problem

Hi, folks. Sorry for bothering, but maybe someone could help me please. The problem is the following: there is some script that copies files from local file system to AFS. The copying is performed with dd command. The script copies data into some AFS volumes. The problem appeared with one... (0 Replies)
Discussion started by: Anta
0 Replies

10. UNIX for Advanced & Expert Users

SSH Problem auth problem

Hi, Just recently we seem to be getting the following error message relating to SSH when we run the UNIX script in background mode: warning: You have no controlling tty. Cannot read confirmation.^M warning: Authentication failed.^M Disconnected; key exchange or algorithm negotiation... (1 Reply)
Discussion started by: budrito
1 Replies
Login or Register to Ask a Question