Sponsored Content
Top Forums Shell Programming and Scripting Remove '.' from file for numbers ending in '.' Post 302935422 by Scrutinizer on Monday 16th of February 2015 01:33:04 PM
Old 02-16-2015
Note that the suggestions test if the preceding character is a digit, not if a field that consists of a number ends with a dot. For example if one of the fields would be A1. then this approach would fail.

An alternative would be to split it into fields and test each field if it is numeric and if it ends in a dot. For example:
Code:
awk '{for(i=1; i<=NF; i++) if($i==$i+0) sub(/\.$/,x,$i)}1' FS=\| OFS=\| file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to remove files with only numbers as file names?

Hi all, I have a bunch of files that are named like 12543, 467249877, etc all over some directories.These files are named only with numbers, they dont have any letters or special characters in their file names. Could you please help me out and give me some command/script to remove only those... (6 Replies)
Discussion started by: praveen_indramo
6 Replies

2. Shell Programming and Scripting

Remove Multiple numbers from file.

Hi, I am trying to cleanup 7 or 10 digits numeric from the file. So for example : Input : 3M Corporation 3M Inc. 888-356-8765 3M Inc. 356-8765 3M Inc. 3568765 3M Inc. 356-8765 3M 8883568765 Inc. Output : 3M Corporation 3M Inc. - - 3M Inc. - 3M Inc. 3M Inc. - (8 Replies)
Discussion started by: msalam65
8 Replies

3. UNIX for Dummies Questions & Answers

how to remove lines ending with '*'

I have a file where some lines end with '*'. I would like to remove those lines ending with '*'. inFile: a b* c d*outFile: a cThank you (7 Replies)
Discussion started by: jdhahbi
7 Replies

4. Shell Programming and Scripting

Help in retrieving the ending line numbers of the functions

Hi! I've a C file which consist of many function definitions with numbers at the beginning as shown below.. 10 void search() 11 { 12 /*body 14 * 15 * 17 * 18 * 40 * 42 * 60 } 90 void func_name() 95 { 99 /*body 100 * 105 * 111 * (7 Replies)
Discussion started by: abk07
7 Replies

5. Shell Programming and Scripting

Remove Numbers from file

I have a file that has some text that looks like this Some Text 1. More text 2. Different text Final Text I would like the remove the lines of text that start with the numbers. Some Text Final Text I have tried to use cat file.txt | grep -Ev 1. >... (9 Replies)
Discussion started by: icculus99
9 Replies

6. Shell Programming and Scripting

Remove ending text

Hello, I am working with a list that contains a large number of files listed by their absolute path. I am trying to determine a way to delete the file name at the end of each line, therefore leaving just the directory path. For example, I'd like to go from: /home/something/file... (2 Replies)
Discussion started by: omnivir
2 Replies

7. Shell Programming and Scripting

Remove certain lines from file based on start of line except beginning and ending

Hi, I have multiple large files which consist of the below format: I am trying to write an awk or sed script to remove all occurrences of the 00 record except the first and remove all of the 80 records except the last one. Any help would be greatly appreciated. (10 Replies)
Discussion started by: nwalsh88
10 Replies

8. UNIX for Advanced & Expert Users

Pring starting and ending numbers using UNIX

Hi all, I need to do scrip for printing starting and ending numbers along with count in given file.:wall: Input: a.txt 10000030 10000029 10000028 10000027 10000026 10000024 10000023 10000021 10000018 10000018 10000017 10000016 10000015 10000014 (2 Replies)
Discussion started by: jackbell2013
2 Replies

9. Shell Programming and Scripting

How to remove the numbers in a file in perl script?

Thanks (1 Reply)
Discussion started by: Raysf
1 Replies

10. UNIX for Beginners Questions & Answers

Remove lines ending with a certain character

I have a file of a content like this: abc_bla -def 800 abc_bla -def 802 abc_bla -def 804 abc_bla -def 806 abc_bla -def 808 abc_bla -def 810 abc_bla -def 812 abc_bla -def 814 ... abc_bla -def 898 abc_bla -def 900 abc_bla -def 902 abc_bla -def 904 ... abc_bla -def 990 abc_bla -def... (7 Replies)
Discussion started by: maya3
7 Replies
magic(4)							   File Formats 							  magic(4)

NAME
magic - file command's magic number file SYNOPSIS
/etc/magic DESCRIPTION
The file(1) command identifies the type of a file using, among other tests, a test for whether the file begins with a certain magic number. The /etc/magic file, or a file specified as an option-argument to the -m or -M options of file(1), specifies what magic numbers are to be tested for, what message to print if a particular magic number is found, and additional information to extract from the file. Each line of the file specifies a position-sensitive test to perform. A test compares the data starting at a particular offset in the file with a 1-byte, 2-byte, 4-byte, or 8-byte numeric value or string. If the test succeeds, a message is printed. The line consists of the fol- lowing fields (separated by tabs): offset type value message offset A number specifying the offset, in bytes, into the file of the data which is to be tested. type The type of the data to be tested. The possible values are: byte, d1, dC A one-byte signed value. short, d2, dS A 2-byte signed value. long, d4, dI, dL, d A 4-byte signed value. llong, d8 An 8-byte signed value ubyte, u1, uC A one-byte unsigned value. ushort, u2, uS A 2-byte unsigned value. ulong, u4, uI, uL, u A 4-byte unsigned value. ullong, u8 An 8-byte unsigned value. string, s A string of bytes. All type specifiers, except for string and s, may be followed by a mask specifier of the form &number. If a mask specifier is given, the value is AND'ed with the number before any comparisons are done. The number is specified in C form. For instance, 13 is decimal, 013 is octal, and 0x13 is hexadecimal. value The value to be compared with the value from the file. If the type is numeric, this value is specified in C form. If it is a string, it is specified as a C string with the usual escapes permitted (for instance, for NEWLINE). Numeric values may be preceded by a character indicating the operation to be performed, as follows: = The value from the file must equal the specified value. < The value from the file must be less than the specified value. > The value from the file must be greater than the specified value. & All the bits in the specified value must be set in the value from the file. ^ At least one of the bits in the specified value must not be set in the value from the file. x Any value will match. If the character is omitted, it is assumed to be "=". For comparison of numeric values, the sign and size of both the value in the file and the value from the value field of the magic entry will match that of the corresponding type field. If there is a non-zero mask (&) in the type field, the comparison will be unsigned. For string values, the byte string from the file must match the specified byte string. The byte string from the file which is matched is the same length as the specified byte string. If the value is a string, it can contain the following sequences: character The backslash-escape sequences \, a, , f, , , , v. octal Octal sequences that can be used to represent characters with specific coded values. An octal sequence consists of a backslash followed by the longest sequence of one, two, or three octal-digit characters(01234567). message The message to be printed if the comparison succeeds. If the string contains a printf(3C) format specification, the value from the file (with any specified masking performed) is printed using the message as the format string. Some file formats contain additional information which is to be printed along with the file type. A line which begins with the character ">" indicates additional tests and messages to be printed. If the test on the line preceding the first line with a ">" succeeds, the tests specified in all the subsequent lines beginning with ">" are performed, and the messages are printed if the tests succeed. The next line which does not begin with a ">" terminates this. FILES
/etc/magic SEE ALSO
file(1), file(1B), printf(3C) NOTES
In Solaris 9 and prior releases, the file utility may have performed unsigned comparisons for types byte, short, and long. Old user-defined magic files, which were specified with the -m option, will need modification of byte, short, and long entries to their corresponding unsigned types (ubyte, ushort, or ulong) for those entries for which all of the following are true: o The entry uses the "<" or the ">" operator. o The type field does not contain a non-zero mask. o The intention of the entry is to test unsigned values. For example, if the following entry is expected to match any non-zero, one-byte value from the file, including values for which the sign bit is on: #offset type value message 0 byte >0 this matches any non-zero value then that entry should be changed to: 0 ubyte >0 this matches any non-zero value In Solaris 7 through Solaris 9, when applying tests for magic file entries whose type field is the numeric type "short" or "long", the file utility in the x86 environment would switch the byte order of the numeric values read. Starting in Solaris 10, the byte order will not be switched on x86. A test for a numeric value whose byte order is identical in both little- and big-endian architectures may require two magic file entries, to ensure that the test correctly identifies files in both environments. For example, a magic file entry that will match on a big-endian system may look like this: 0 long 0xf00000ff extended accounting file Its corresponding magic file entry that will match the same value on a little-endian system would look like this: 0 long 0xff0000f0 extended accounting file BUGS
There should be more than one level of subtests, with the level indicated by the number of `>' at the beginning of the line. SunOS 5.11 6 Feb 2004 magic(4)
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy