03-13-2008
Printing value with no obvious field seperator
Hi all,
Can anybody think of a way to do this? I have a file with content like the following:
F_TOP_PARAM_VALUE[0]F_TOP_SOURCE[UD1]F_TOP_DEL_NOTIFICATION[N]F_DEST_ADDR[76849]F_TOP_DEL_TYPE
What I want to do is print out the value in the square brackets after F_TOP_SOURCE. So in this case I'd like to print UD1 for this line. The file contains multiple lines such as the above and the number of parameters listed in the file can change which means that F_TOP_SOURCE[???] won't always be the second paramter list - so I could have a file with two lines like:
F_TOP_PARAM_VALUE[0]F_TOP_SOURCE[UD1]F_TOP_DEL_NOTIFICATION[N]F_DEST_ADDR[76849]F_TOP_DEL_TYPE
F_TOP_ORIG[6547]F_TOP_PARAM_VALUE[0]F_TOP_SOURCE[PS1]F_TOP_DEL_NOTIFICATION[N]F_DEST_ADDR[76849]F_TOP_DEL_TYPE
Any ideas? The only thing I can be sure about is that "F_TOP_SOURCE" will always precede the value in the bracket that I want, and an "F" will always follow the bracket I want.
Nightmare!
Any help would be much appreciated. I think it's also worth noting that I didn't design the format of the file!
Thanks in advance
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I wrote a script on HPUX 11.11 to turn a Decimal subnet mask (255.255.254.0) to hex 0xfffffe00 (subset of a bigger script). It works great on the HPUX systems but on the freebsd box the awk is not seperating the fields properly. I tried to google for a solution and seaching these forums i am just... (3 Replies)
Discussion started by: insania
3 Replies
2. UNIX for Advanced & Expert Users
Hai
I am using
bash-2.03$ bash --version
GNU bash, version 2.03.0(1)-release (sparc-sun-solaris)
I am not able to use gawk command its showing command not found , why ?
Eg:
awk 'NR==1' fix.txt | gawk 'BEGIN { FIELDWIDTHS = "3 2" } { printf($1"|"$2); }'... (8 Replies)
Discussion started by: tkbharani
8 Replies
3. Shell Programming and Scripting
Hi,
How do i Print anything after a ':'
Ex :
file1: 1235131(rs32553)
I want to print out "1235131(rs32553)"
how do i do it. I know we can do this using awk but looking for the right syntax.
Any help appreciated.
Thanks,
Ram (7 Replies)
Discussion started by: ramky79
7 Replies
4. Shell Programming and Scripting
Hi Please help me out with this problem:
I want to have a script that would change the nth field seperator in a line into something else.
like
a,d,4,2,97,8,9
into
a,d,4,2,97/8/9
Thanks (2 Replies)
Discussion started by: onthetopo
2 Replies
5. Shell Programming and Scripting
in csh
set x = "/home/usr/dir1/file1"
if i do:
echo $x | awk -F\/ '{print $NF}'
will result to:
"file1"
how do i invert the output to:
"/home/usr/dir1"
:confused: (2 Replies)
Discussion started by: jehrome_rando
2 Replies
6. Shell Programming and Scripting
"355"|""|"NJ"|"A0A 1W0"|"V"|""|""|""|"N"
I've the above sample data seperated with pipe delimeter and in the file I want to replace a space with "|" to the 4th field so the result would be like below. So it would change from 9 fields to 10 fields.
"355"|""|"NJ"|"A0A"|"1W0"|"V"|""|""|""|"N"
... (3 Replies)
Discussion started by: rudoraj
3 Replies
7. Shell Programming and Scripting
Is there a way I could use different a different field seperator for different parts of the body?
kinda like
{FS = ":"}
FILENAME == "products"{
price = $3
if(numprods < $1-100)
numprods = $1-100
}
{FS = "/"}{}
FILENAME == "associates"{
associateid... (5 Replies)
Discussion started by: angermanaged
5 Replies
8. Shell Programming and Scripting
hi guys im very new to scripting and i have a problem. i need to use awk in my script and the script needs to print the max for each of the columns in a file. for example:
numbers.txt
10 15 20 30 40
58 25 30 15 10
38 10 38 8 9
./max numbers.txt
58 25 38 30 40
i have no clue on how to... (4 Replies)
Discussion started by: youness
4 Replies
9. Shell Programming and Scripting
Hi All,
I am searching for a script which will produce an output file with the uniq first field with the second field having highest value among all the duplicates..
The output file will produce only the uniqs which are duplicate 3 times..
Input file
X 9
B 5
A 1
Z 9
T 4
C 9
A 4... (13 Replies)
Discussion started by: ailnilanjan
13 Replies
10. UNIX for Beginners Questions & Answers
Hi, input data format:
echo ' <APPLICATION="APPLSG" SUB_APPLICATION="DLY" JOBNAME="DPL_BN_RE_CCMS_SA" CMDLINE="run_job.ksh %%PARAM1 %%PARAM2" TASKTYPE="Command" />'
expected format:
"APPLSG", "DLY", "DPL_BN_RE_CCMS_SA", "run_job.ksh %%PARAM1 %%PARAM2"
my command:
echo ' ... (2 Replies)
Discussion started by: JSKOBS
2 Replies
magic(5) File Formats Manual magic(5)
Name
magic - magic file for the file command
Syntax
/usr/lib/file/magic
Description
The magic file is used by the command to identify files that have some sort of magic number. A magic number is any numeric or string con-
stant that identifies the file containing the constant.
The file is formatted as follows:
Byte offset
The byte offset is where information is found in the file. This is the number of bytes from the beginning of the file to the first
byte of the magic number or string. This may, optionally, be preceded by a right angle bracket (>) to indicate a continuation line to
supply extra information in the printed message.
Value type
The value type is the type of the information to be found at the specified byte offset. The file data is interpreted as the following
valid types:
byte Unsigned char type
short Unsigned short type
long Long type
string Character (byte) string
Optional operator
Describes how the value specified here should be compared with the data at the desired offset. Valid operator characters are: an
equal sign, a right angle bracket, and a left angle bracket (=, >, <). If none is specified, = is assumed.
Value
The value to match. Numeric values may be decimal, octal, or hexadecimal. String values are defined as regular expressions here. The
regular expressions used here are extended in two ways from regular expression definition in ed(1).
1. Normally unprintable characters may be escaped with a backslash (). The special characters
, ,
, and f are allowed.
An octal representation can also be used to insert any desired byte value, except 0. Normally, regular expression cannot
handle such character values. Because the backslash is used as an escape character while the regular expression is being
read in, normal occurrences of a backslash in a regular expression must be escaped with a second backslash. As an example, (
must be written as \( and . must be written as \.
2. Text found in a file can also be inserted in the printed string with the use of the \% delimiter. All text found between
these delimiters is substituted into the print string.
This regular expression search never terminates until a match is explicitly found or rejected. The special character
is a
valid character in the patterns. Therefore, the pattern .* should never be used here.
major, minor type
The major and minor file type numbers are not used by the command.
String to print
Any desired text string. Data from the file can be included with the use of continuation lines beginning with a right angle bracket
(>). Two types of continuation lines are possible, depending on the sign of the byte offset entry.
If the byte offset is positive, the specified data can be printed in the string when requested with an appropriate format.
If the offset is a negative number, an internal routine will be called to test if a particular string is necessary and, if so, to
return it.
The byte offset number is an index to an internal table of routines available for use. Two such routines are currently defined, both
for a.out images:
Byte Offset Returned String(s)
-1: ["old version 7 style symbol table"]
-2: ["setuid "]["setgid "]["sticky "]
Examples
The following is an example of a script. The second line adds setuid, setgid text, if appropriate:
0 string ^#![ ]*\%[^ 0*\% 7,4 %s
>-2 long 0 7,4 %sscript
The following is an example of an executable image:
>-1 long 0 12,3 %s
0 short 0413 12,4 demand paged pure
>2 short 02 12,4 POSIX
>2 short 01 12,4 SVID
>-2 long 0 12,4 %sexecutable
>16 long >0 12,4 not stripped
The following is an example of a text file:
0 string ^ 1h[0-9][0-9][0-9][0-9][0-9] 7,1 sccsfile
Files
See Also
file(1)
magic(5)