Sponsored Content
Top Forums Shell Programming and Scripting Extracting formatted text and numbers Post 302406401 by alister on Monday 22nd of March 2010 07:10:58 PM
Old 03-22-2010
Hello, DFr0st:

Your sample data in a file called data:
Code:
$ cat data
1964.01.17 121427.6 24.268s 177.074w 158.0km 4.8 Tonga 1
ep :aang= -18.5 90% : l=267.9,az= -18.5,pl=35.9
ellipse: a= 188.6 ellipsoid: l= 59.3,az= 158.6,pl=54.0
(90% ) : b= 25.2 semi-axis: l= 29.4,az=-109.5,pl= 1.4
1964.01.18 41437.6 30.000s 177.900w 48.0km 4.8 Tonga

Passing it through a tr filter to remove all characters that are not a decimal digit, decimal point, minus sign, space, or newline yields:
Code:
$ tr -cd '[-0-9. \n]' < data
1964.01.17 121427.6 24.268 177.074 158.0 4.8  1
  -18.5 90  267.9 -18.535.9
  188.6   59.3 158.654.0
90    25.2 -  29.4-109.5 1.4
1964.01.18 41437.6 30.000 177.900 48.0 4.8

Assuming that your sample data is representative of the two forms of records you mentioned, and that you did not neglect to mention any special cases, a line with 6 numbers is a single line record that only requires appending three zeros; a line with 7 numbers is the start of a multiline record and is followed by three lines of 4, 3, and 5 fields respectively (all field counts are after tr filtering). The following AWK assembles what remains into what's desired, before passing it through another tr filter to squeeze mulitple spaces into a single space:
Code:
$ tr -cd '[-0-9. \n]' < data | awk 'NF==6{print $0,0,0,0} NF==7{$2=""; $NF=""; s=$0; getline; d=$1; getline; a=$1; getline; print s,d,a,$2}' | tr -s ' '
1964.01.17 24.268 177.074 158.0 4.8 -18.5 188.6 25.2
1964.01.18 41437.6 30.000 177.900 48.0 4.8 0 0 0

Regards,
Alister

Last edited by alister; 03-22-2010 at 10:56 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert DATE string to a formatted text

Hi guys, i need your help. I need to convert a date like this one 20071003071023 , to a formated date like 20071003 07:10:23 . Could this be possible ? Regards, Osramos (6 Replies)
Discussion started by: osramos
6 Replies

2. Shell Programming and Scripting

Script or command: Formatted text to CSV

Hi Everyone, I've been using this site as a great resource to aid me with simple search and replace tasks. I still consider myself a novice and now I've been pulling my hair out over this problem. Any hints or suggestions would be welcome! I have a text file in a format like this name:... (6 Replies)
Discussion started by: regexnub
6 Replies

3. Shell Programming and Scripting

print formatted text to the printer

Hello!!! I am using shell script that print some formated text on the screen (example) ======== hello I am ... ======== Is it possible to print this information to the printer exactly as I see it on the screen??? (6 Replies)
Discussion started by: tdev457
6 Replies

4. UNIX for Dummies Questions & Answers

Print numbers and associated text belonging to an interval of numbers

##### (0 Replies)
Discussion started by: lucasvs
0 Replies

5. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

Extracting lines from text files in folder based on the numbers in another file

Hello, I have a file ff.txt that looks as follows *ABNA.txt 356 24 36 112 *AC24.txt 457 458 321 2 ABNA.txt and AC24.txt are the files in the folder named foo1. Based on the numbers in the ff.txt file, I want to extract the lines from the corresponding files in the foo1 folder and... (2 Replies)
Discussion started by: mohamad
2 Replies

7. Shell Programming and Scripting

Extracting numbers

Hi I am part of a academic organization and I want to send a fax to the students however there must be a quicker way to get the fax numbers extracted from the online forms they sent me. The file looks like this (numbers are fake in order to protect identity): Biochemistry Major Michael... (3 Replies)
Discussion started by: phil_heath
3 Replies

8. Shell Programming and Scripting

Split files with formatted numbers

How to split the file and have suffix with formatted numbers Tried the following code awk '{filename="split."int((NR-1)/2)".txt"; print >> filename}' split.txt Current Result Expected Result (21 Replies)
Discussion started by: bobbygsk
21 Replies

9. Shell Programming and Scripting

Extracting values based on line-column numbers from multiple text files

Dear All, I have to solve the following problems with multiple tab-separated text file but I don't know how. Any help would be greatly appreciated. I have access to Linux mint (but not as a professional). I have multiple tab-delimited files with the following structure: file1: 1 44 2 ... (5 Replies)
Discussion started by: Bastami
5 Replies

10. Shell Programming and Scripting

Sum up formatted numbers with comma separation

I need to sum up the values in field nr 5 in a data file that contains some file listing. The 5th field denotes the size of each file and following are some sample values. 1,775,947,633 4,738 7,300 16,610 15,279 0 0 I tried the following code in a shell script. awk '{sum+=$5} END{print... (4 Replies)
Discussion started by: krishmaths
4 Replies
SNMPDELTA(1)							     Net-SNMP							      SNMPDELTA(1)

NAME
snmpdelta - Monitor delta differences in SNMP Counter values SYNOPSIS
snmpdelta [ common options ] [-Cf] [ -Ct ] [ -Cs ] [ -CS ] [ -Cm ] [ -CF configfile ] [ -Cl ] [ -Cp period ] [ -CP Peaks ] [ -Ck ] [ -CT ] AGENT OID [ OID ... ] DESCRIPTION
snmpdelta will monitor the specified integer valued OIDs, and report changes over time. AGENT identifies a target SNMP agent, which is instrumented to monitor the given objects. At its simplest, the AGENT specification will consist of a hostname or an IPv4 address. In this situation, the command will attempt communication with the agent, using UDP/IPv4 to port 161 of the given target host. See snmpcmd(1) for a full list of the possible formats for AGENT. OID is an object identifier which uniquely identifies the object type within a MIB. Multiple OIDs can be specified on a single snmpdelta command. OPTIONS
COMMON OPTIONS Please see snmpcmd(1) for a list of possible values for COMMON OPTIONS as well as their descriptions. -Cf Don't fix errors and retry the request. Without this option, if multiple oids have been specified for a single request and if the request for one or more of the oids fails, snmpdelta will retry the request so that data for oids apart from the ones that failed will still be returned. Specifying -Cf tells snmpdelta not to retry a request, even if there are multiple oids specified. -Ct Flag will determine time interval from the monitored entity. -Cs Flag will display a timestamp. -CS Generates a "sum count" in addition to the individual instance counts. The "sum count" is the total of all the individual deltas for each time period. -Cm Prints the max value ever attained. -CF configfile Tells snmpdelta to read it's configuration from the specified file. This options allows the input to be set up in advance rather than having to be specified on the command line. -Cl Tells snmpdelta to write it's configuration to files whose names correspond to the MIB instances monitored. For example, snmpdelta -Cl localhost ifInOctets.1 will create a file "localhost-ifInOctets.1". -Cp Specifies the number of seconds between polling periods. Polling constitutes sending a request to the agent. The default polling period is one second. -CP peaks Specifies the reporting period in number of polling periods. If this option is specified, snmpdelta polls the agent peaks number of times before reporting the results. The result reported includes the average value over the reporting period. In addition, the highest polled value within the reporting period is shown. -Ck When the polling period (-Cp) is an increment of 60 seconds and the timestamp is displayed in the output (-Cs), then the default display shows the timestamp in the format hh:mm mm/dd. This option causes the timestamp format to be hh:mm:ss mm/dd. -CT Makes snmpdelta print its output in tabular form. -Cv vars/pkt Specifies the maximum number of oids allowed to be packaged in a single PDU. Multiple PDUs can be created in a single request. The default value of variables per packet is 60. This option is useful if a request response results in an error becaues the packet is too big. EXAMPLES
$ snmpdelta -c public -v 1 -Cs localhost IF-MIB::ifInUcastPkts.3 IF-MIB::ifOutUcastPkts.3 [20:15:43 6/14] ifInUcastPkts.3 /1 sec: 158 [20:15:43 6/14] ifOutUcastPkts.3 /1 sec: 158 [20:15:44 6/14] ifInUcastPkts.3 /1 sec: 184 [20:15:44 6/14] ifOutUcastPkts.3 /1 sec: 184 [20:15:45 6/14] ifInUcastPkts.3 /1 sec: 184 [20:15:45 6/14] ifOutUcastPkts.3 /1 sec: 184 [20:15:46 6/14] ifInUcastPkts.3 /1 sec: 158 [20:15:46 6/14] ifOutUcastPkts.3 /1 sec: 158 [20:15:47 6/14] ifInUcastPkts.3 /1 sec: 184 [20:15:47 6/14] ifOutUcastPkts.3 /1 sec: 184 [20:15:48 6/14] ifInUcastPkts.3 /1 sec: 184 [20:15:48 6/14] ifOutUcastPkts.3 /1 sec: 184 [20:15:49 6/14] ifInUcastPkts.3 /1 sec: 158 [20:15:49 6/14] ifOutUcastPkts.3 /1 sec: 158 ^C $ snmpdelta -c public -v 1 -Cs -CT localhost IF-MIB:ifInUcastPkts.3 IF-MIB:ifOutcastPkts.3 localhost ifInUcastPkts.3 ifOutUcastPkts.3 [20:15:59 6/14] 184.00 184.00 [20:16:00 6/14] 158.00 158.00 [20:16:01 6/14] 184.00 184.00 [20:16:02 6/14] 184.00 184.00 [20:16:03 6/14] 158.00 158.00 [20:16:04 6/14] 184.00 184.00 [20:16:05 6/14] 184.00 184.00 [20:16:06 6/14] 158.00 158.00 ^C The following example uses a number of options. Since the Cl option is specified, the output is sent to a file and not to the screen. $ snmpdelta -c public -v 1 -Ct -Cs -CS -Cm -Cl -Cp 60 -CP 60 interlink.sw.net.cmu.edu .1.3.6.1.2.1.2.2.1.16.3 .1.3.6.1.2.1.2.2.1.16.4 fi SEE ALSO
snmpcmd(1), variables(5). 4th Berkeley Distribution 25 Jul 2003 SNMPDELTA(1)
All times are GMT -4. The time now is 05:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy