Sponsored Content
Top Forums Shell Programming and Scripting Extracting character between 2 token - using only first match Post 302896852 by wisecracker on Wednesday 9th of April 2014 01:57:30 PM
Old 04-09-2014
Longhand using __builtins__, OSX 10.7.5, default bash terminal...
Code:
#!/bin/bash
# 3214.sh
ifs_str="$IFS"
IFS="
"
echo "2638 ? 00:00:01 kworker/u8:0
2755 ? 00:00:00 pickup
3111 ? 00:00:00 kworker/u8:2
3127 ? 00:00:00 kwrite
3132 ? 00:00:00 kworker/0:2
3134 ? 00:00:00 kworker/2:2
3141 ? 00:00:00 kworker/0:0
3167 ? 00:00:00 kworker/2:0
3168 ? 00:00:00 kworker/u8:1
3214 ? 00:00:01 acroread
3334 pts/1 00:00:00 ps " > /tmp/3214.txt
line_number=1
while read line
do
	if [ "${line:0:4}" == "3214" ]
	then
		printf "3214" > /tmp/3214.text
		printf "\nLine number=$line_number...\n\n"
	fi
	line_number=$(( $line_number + 1 ))
done < /tmp/3214.txt
cat < /tmp/3214.text
IFS="$ifs_str"
exit 0

Results:-
Code:
Last login: Wed Apr  9 18:22:18 on ttys000
AMIGA:barrywalker~> chmod 755 3214.sh
AMIGA:barrywalker~> ./3214.sh

Line number=10...

3214AMIGA:barrywalker~> _

Also the line number it is on as a bonus too... ;o)
Note: The "3214" without a newline...

(Rigged for silent running for a while.)
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting lines that match string at certain position

I have a fixed length file in the following format <date><product_code><other data> The file size is huge and I have to extract only the lines that match a certain product code which is of 2 bytes length. I cannot use normal grep since that may give undesirable results. When I search for prod... (5 Replies)
Discussion started by: paruthiveeran
5 Replies

2. Shell Programming and Scripting

help extracting a matching pattern and next lines of match

Hi there, i'm having some problems just making an awk script (i've tried this way, but other way can be posible for sure), for the next file file.txt <register> <createProfile> <result>0</result> <description><!]></description> <msisdn>34661461174</msisdn> <inputOmvID>1</inputOmvID>... (6 Replies)
Discussion started by: vicious
6 Replies

3. Shell Programming and Scripting

Extracting first character from a user response

I am using the following code in a CShell script to get a yes/no response from the user: echo "" echo -n "Do you want to archive your main level directory? <y> or n: " set main_answer = $< Is there a way to extract the first letter from the user's response and then perhaps convert that... (4 Replies)
Discussion started by: phudgens
4 Replies

4. Shell Programming and Scripting

Extracting the last character of a string

How to extract the last character of a string in bash? ---------- Post updated at 03:56 PM ---------- Previous update was at 03:55 PM ---------- Suppose "abcde" is a string. i want to extract the last character i.e. "e". (1 Reply)
Discussion started by: proactiveaditya
1 Replies

5. Shell Programming and Scripting

Extracting N lines match number X of a pattern

Hi All, as the title says I need to extract N lines after match number X of a pattern. e.g. 111 xxx xxx 111 yyy yyy 111 www www 111 zzz zzz I would like to extract the two lines after the second 111 occurrence. I tried with grep but I didn't find any options to do that. Any... (11 Replies)
Discussion started by: f_o_555
11 Replies

6. Shell Programming and Scripting

BASH: extracting values from multiple lines after a match

Hi there, I have the following output, # raidctl -l RAID Volume RAID RAID Disk Volume Type Status Disk Status ------------------------------------------------------ c0t1d0 IM OK c0t1d0 OK ... (4 Replies)
Discussion started by: rethink
4 Replies

7. UNIX for Dummies Questions & Answers

extracting character

This time I am trying to extract the number 10 from the following line. This number is subject to change and may be anything from 1 to 3 numerals in length, i.e. 1-999. Hence why I dont want to use 'cut' cmd. The line I am working on is GGSN-MIB::ggsnApnName.10 = STRING: open.internetI have... (7 Replies)
Discussion started by: rob171171
7 Replies

8. Shell Programming and Scripting

Q:Perl Extracting & Printing Security Token

I have a script which is supposed to log in to my vB account and print my security token, however doesn't seem to work globally. The logging in works perfectly just will not retrieve and print the security token for every forum I log in to. Code Below: #!/usr/bin/perl use LWP::UserAgent; ... (8 Replies)
Discussion started by: AndrewTwain
8 Replies

9. Shell Programming and Scripting

sed - extracting the first word only if match

Hello. from a text file, I want to get only the first word ( before blank ) following code= grep -i -e "WORD1" "/path/to/text/file.txt | sed -n 's/WORD1\+//p' | sed -n 's/code=/\1/p' return an error. sed: -e expression #1, char 12: invalid reference \1 on `s' command's RHSFor debugging... (12 Replies)
Discussion started by: jcdole
12 Replies

10. Shell Programming and Scripting

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies
pkgmap(4)							   File Formats 							 pkgmap(4)

NAME
pkgmap - package contents description file DESCRIPTION
pkgmap is an ASCII file that provides a complete listing of the package contents. It is automatically generated by pkgmk(1) using the information in the prototype(4) file. Each entry in pkgmap describes a single ``deliverable object file.'' A deliverable object file includes shell scripts, executable objects, data files, directories, and so forth. The entry consists of several fields of information, each field separated by a space. The fields are described below and must appear in the order shown. part An optional field designating the part number in which the object resides. A part is a collection of files and is the atomic unit by which a package is processed. A developer can choose the criteria for grouping files into a part (for exam- ple, based on class). If no value is defined in this field, part 1 is assumed. ftype A one-character field that indicates the file type. Valid values are listed below. File types are divided between those that are not to be modified and those that are modifiable. Files of the following types must never be modified: b block special device c character special device d directory f a standard executable file, data file, or other type of file, the contents of which must never be modified. i information file (such as a file containing a copyright, list of dependencies, or package information) or instal- lation script (such as checkinstall, class action [i.], pre/post install/remove), the contents of which must never be modified. l linked file p named pipe s symbolic link x an exclusive directory accessible only by this package Files of the following types can be modified: e An editable file, intended to be edited (selectively modified) after installation. An editable file is expected to change on installation or removal, can be shared by several packages, and must be installed by a class action script. Examples are a configuration file or a list of users. v A volatile file, intended to be overwritten or appended to after installation. A volatile file is not expected to change on installation or removal, is not preserved between installations, and can be installed by a class action script. Examples are a log file or a lock file. Following package installation, the contents of files of all types except e and v must not change. Any file that is subject to change should be marked as e or v. class The installation class to which the file belongs. This name must contain only alphanumeric characters and be no longer than 12 characters. It is not specified if the ftype is i (information file). pathname pathname may contain variables of the form $variable that support install-time configuration of the file. variable may be embedded in the pathname structure. (See prototype(4) for definitions of variable specifications.) Do not use the following reserved words in pathname, since they are applied by pkgadd(1M) using a different mechanism: PKG_INSTALL_ROOT BASEDIR CLIENT_BASEDIR major The major device number. The field is only specified for block or character special devices. minor The minor device number. The field is only specified for block or character special devices. mode The octal mode of the file (for example, 0664). A question mark (?) indicates that the mode will be left unchanged, imply- ing that the file already exists on the target machine. This field is not used for linked files, packaging information files, or non-installable files. The mode can contain a variable specification. (See prototype(4) for definitions of variable specifications.) owner The owner of the file (for example, bin or root). The field is limited to 14 characters in length. A question mark (?) indicates that the owner will be left unchanged, implying that the file already exists on the target machine. This field is not used for linked files or non-installable files. It is used optionally with a package information file. If used, it indicates with what owner an installation script will be executed. The owner can contain a variable specification. (See prototype(4) for definitions of variable specifications.) group The group to which the file belongs (for example, "bin" or "sys"). The field is limited to 14 characters in length. A ques- tion mark (?) indicates that the group will be left unchanged, implying that the file already exists on the target machine. This field is not used for linked files or non-installable files. It is used optionally with a package information file. If used, it indicates with what group an installation script will be executed. The group can contain a variable specification. (See prototype(4) for definitions of variable specifications.) size The actual size of the file in bytes. This field is not specified for named pipes, special devices, directories or linked files. cksum The checksum of the file contents. This field is not specified for named pipes, special devices, directories, or linked files. modtime The time of last modification, as reported by the stat(2) function call. This field is not specified for named pipes, spe- cial devices, directories, or linked files. Each pkgmap file must have one line that provides information about the number of parts, maximum size of parts that make up the package, and, optionally, the size of the package after compression (where size is given in 512-byte blocks). This line is in the following format: : number_of_parts maximum_part_size compressed_pkg_size Lines that begin with ``#'' are comment lines and are ignored. When files are saved during installation before they are overwritten, they are normally just copied to a temporary pathname. However, for files whose mode includes execute permission (but which are not editable), the existing version is linked to a temporary pathname and the original file is removed. This allows processes which are executing during installation to be overwritten. EXAMPLES
Example 1: A sample pkgmap file : 2 500 1 i pkginfo 237 1179 541296672 1 b class1 /dev/diskette 17 134 0644 root other 1 c class1 /dev/rdiskette 17 134 0644 root other 1 d none bin 0755 root bin 1 f none bin/INSTALL 0755 root bin 11103 17954 541295535 1 f none bin/REMOVE 0755 root bin 3214 50237 541295541 1 l none bin/UNINSTALL=bin/REMOVE 1 f none bin/cmda 0755 root bin 3580 60325 541295567 1 f none bin/cmdb 0755 root bin 49107 51255 541438368 1 f class1 bin/cmdc 0755 root bin 45599 26048 541295599 1 f class1 bin/cmdd 0755 root bin 4648 8473 541461238 1 f none bin/cmde 0755 root bin 40501 1264 541295622 1 f class2 bin/cmdf 0755 root bin 2345 35889 541295574 1 f none bin/cmdg 0755 root bin 41185 47653 541461242 2 d class2 data 0755 root bin 2 p class1 data/apipe 0755 root other 2 d none log 0755 root bin 2 v none log/logfile 0755 root bin 41815 47563 541461333 2 d none save 0755 root bin 2 d none spool 0755 root bin 2 d none tmp 0755 root bin SEE ALSO
pkgmk(1), pkgadd(1M), stat(2), pkginfo(4), prototype(4) Application Packaging Developer's Guide NOTES
The pkgmap file may contain only one entry per unique pathname. SunOS 5.10 13 Feb 2004 pkgmap(4)
All times are GMT -4. The time now is 07:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy