Sponsored Content
Full Discussion: Extract a string from file
Top Forums Shell Programming and Scripting Extract a string from file Post 302374904 by He2 on Wednesday 25th of November 2009 08:52:16 PM
Old 11-25-2009
Power problem AWK script

Friends;
I have little experience with shell and I am not able to resolve this

problem:

file1:
CRA-JJ-W980-01; 2009-11-24; GigabitEthernet; 0/0
CRA-JJ-W980-01; 2009-11-24; GigabitEthernet;1/0
CRA-JJ-W980-01;2009-11-24;GigabitEthernet;3/0
CRA-JJ-W980-01;2009-11-24;GigabitEthernet;5/0
CRA-JJ-W980-01;2009-11-24;ATM;13/0
CRA-JJ-W980-01;2009-11-24;ATM;14/0
CRA-JJ-W980-01;2009-11-24;ATM;15/0

File2:
CRA-JJ-W980-01;2009-11-24;0/0/0;6967
CRA-JJ-W980-01;2009-11-24;1/0/0;5035
CRA-JJ-W980-01;2009-11-24;3/0/0;3937
CRA-JJ-W980-01;2009-11-24;5/0/1;5745
CRA-JJ-W980-01;2009-11-24;11/0/0;1786
CRA-JJ-W980-01;2009-11-24;11/0/1;2376
CRA-JJ-W980-01;2009-11-24;13/0/0;925
CRA-JJ-W980-01;2009-11-24;13/0/1;1254
CRA-JJ-W980-01;2009-11-24;13/0/2;772
CRA-JJ-W980-01;2009-11-24;13/0/3;690
CRA-JJ-W980-01;2009-11-24;14/0/0;515
CRA-JJ-W980-01;2009-11-24;14/0/1;179
CRA-JJ-W980-01;2009-11-24;14/0/2;860
CRA-JJ-W980-01;2009-11-24;14/0/3;677
CRA-JJ-W980-01;2009-11-24;15/0/0;806
CRA-JJ-W980-01;2009-11-24;15/0/1;98
CRA-JJ-W980-01;2009-11-24;15/0/2;894
CRA-JJ-W980-01;2009-11-24;15/0/3;353

compare column 3 of file 2 and column 4 file 1. as in column 4 of file 1 is contained in the 2nd column 3.

eg
> Line 1 of file 1:
CRA-JJ-W980-01;2009-11-24;GigabitEthernet;0/0

> Line 1 of file 2:
CRA-JJ-W980-01;2009-11-24;0/0/0;6967

0/0/0 contains the beginning 0/0

then I would file a 3 with the following output:

File3:
CRA-JJ-W980-01;2009-11-24;0/0/0;GigabitEthernet
CRA-JJ-W980-01;2009-11-24;1/0/0;GigabitEthernet
CRA-JJ-W980-01;2009-11-24;3/0/0;GigabitEthernet
CRA-JJ-W980-01;2009-11-24;5/0/1;GigabitEthernet
CRA-JJ-W980-01;2009-11-24;13/0/0;ATM
CRA-JJ-W980-01;2009-11-24;13/0/1;ATM
CRA-JJ-W980-01;2009-11-24;13/0/2;ATM
CRA-JJ-W980-01;2009-11-24;13/0/3;ATM
CRA-JJ-W980-01;2009-11-24;14/0/0;ATM
CRA-JJ-W980-01;2009-11-24;14/0/1;ATM
CRA-JJ-W980-01;2009-11-24;14/0/2;ATM
CRA-JJ-W980-01;2009-11-24;14/0/3;ATM
CRA-JJ-W980-01;2009-11-24;15/0/0;ATM
CRA-JJ-W980-01;2009-11-24;15/0/1;ATM
CRA-JJ-W980-01;2009-11-24;15/0/2;ATM
CRA-JJ-W980-01;2009-11-24;15/0/3;ATM

Thank you.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a string from a file

Input File: ===================================== "Server1" srvgrp="group1" srvid=10 CLOPT="-A -r -e /path/logfile -o /path/stdout" VAR1=0666 VAR2=N VAR3=0666 MIN=3 VAR4=4 VAR5=N VAR6=FASTPATH VAR7=5 VAR8=86400 VAR9=Y ... (20 Replies)
Discussion started by: kaustubh137
20 Replies

2. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

3. Shell Programming and Scripting

Find a string and extract a value from a file

I have a file where a line has the following form: n0=7.00 !Central density and I want to extract the value 7.00. I used to do this with the order below, which finds the string "n0" and take the rest of the line parting from the separator "=", but the comment "Central density..."... (7 Replies)
Discussion started by: josegr
7 Replies

4. Shell Programming and Scripting

Extract string from a file & write to a new file (Perl)

Hi, This is the first time playing around with perl and need some help. Assuming if i have a line of text that looks like this: Date/Time=Nov 18 17:12:11;Device Name=192.168.1.1;Device IP=192.168.1.1;Device Class=IDS;Source IP=155.212.212.111;Source Name=UNKNOWN;Source Port=1679... (3 Replies)
Discussion started by: LuckyGuy
3 Replies

5. Shell Programming and Scripting

awk extract a string from a file

Hi, I have a file which has thousand of lines with lines starting with And I want to extract and show to user only the below string from all the lines Please note note that the above string is a time stamp and it would be different on all the lines. Please tell me how to extract... (8 Replies)
Discussion started by: jredx
8 Replies

6. Shell Programming and Scripting

Extract a string between 2 ref string from a file

Hi, May i ask if someone share some command for extracting a string between 2 ref string in a txt file My objective: i had a file with multiple lines and wants only to extract the string "watch?v=IbkAXOmEHpY" or "watch?v=<11 random character>", when i used "grep 'watch?=*' i got a results per... (4 Replies)
Discussion started by: jao_madn
4 Replies

7. Shell Programming and Scripting

extract string from file name between two underscores

Hi, Here is my question, I need to extract string between two underscores from the filename for example, filename is atmos_8xdaily_instant_300x300_1_12.nc what I want to extract is 300x300. There are many such files in my directory, so I guess the code should be like: for file... (7 Replies)
Discussion started by: 1988PF
7 Replies

8. Shell Programming and Scripting

Extract a specific string from a file

Hi, I have a file whose contents are as follows. 2013-03-08/15:09:20.134 INFO 00000000-00000000 0034 09700400 CON_IN SessionID:ED5E1400-4805-85E2-17B2-5BE45684886A Connection ID:ED5E1400-4805-68F1-BB1D-F06496BCF910 TO:<sip:51234999@10.239.94.146:5060 FROM:<sip:9302280716@97.208.31.7:51024... (2 Replies)
Discussion started by: SunilB2011
2 Replies

9. Shell Programming and Scripting

Need to extract a String from log file

Hi i am having a logfile which contain lot of entires, but i need extract a word after if i found a line that contains a particular string as "ENROLLMENT_EXCEPTION - Exception". please help me in getting a script to do this. Regards C. Suresh (5 Replies)
Discussion started by: sumeeva1907
5 Replies

10. Shell Programming and Scripting

Extract a string from a file

I have a file with below contents. INCLUDE INCLUDE SYSLIB(SANJ) INCLUDE SYSLIB(BIS) NAME BQTFL(R) dfdg fgbb NAME B i want to grep for "INCLUDE SYSLIB" in the file and do some operation so that my output will be in the bracketed value as below. SANJ BIS Pls let me know how can i... (7 Replies)
Discussion started by: millan
7 Replies
rmsf(1M)																  rmsf(1M)

NAME
rmsf - remove a special (device) file SYNOPSIS
directory] special_file ... class | driver] directory] hw_path DESCRIPTION
The command removes one or more special files from the directory and potentially removes information about the associated device or devices with H/W type or a (see ioscan(1M)) from the system. If no options are specified, removes only the special_file specified on the command line. The option causes to remove the definition of the device from the system without removing any special files. The option causes to remove the device definition and all special files that map to it from the directory (or the directory specified with the option). When the specified special_file or hw_path belongs to a persistent device type, the device corresponding to special_file or hw_path should not be in an open state in order for the command to complete successfully. When the option is used along with a persistent device type special_file or LUN hw_path, the command executes and displays Critical Resource Analysis (CRA) on the corresponding device before removing the special_file or hw_path. Other than with persistent device type special_file or LUN hw_path, the option will be ignored by the command for any other type of special_file or hw_path. Use of the (quiet) option along with suppresses the display of Critical Resource Analysis (CRA) report. Without the option, if special_file is specified with a relative path, the path is treated relative to the default device directory If spe- cial_file is specified with an absolute path and the option is also used, the special_file with absolute path will have precedence over the option. Note that if special_file belongs to a node for which H/W type is not the device definition will not be removed from the system and the special_file will be removed if it is a leaf node. If a is specified, special files are removed as follows: o If hw_path belongs to a node with H/W type all special files mapping to devices at that hardware path and the system definition of those devices are removed. If the hw_path belongs to LUN hardware path of a node of type the device should not be in an open state for the command to complete successfully. o If hw_path belongs to a node with H/W type all legacy special files mapping to devices at that hardware path, as well as the sys- tem definition of those devices, are removed. o If hw_path belongs to a node for which H/W type is no special files are removed; only corresponding node is removed. o If hw_path belongs to a node for which H/W type is not any of the above mentioned types, then a special file is removed as fol- lows: o If it is a leaf node, only special files for that node will be removed. o If the node has children, then a warning message will be issued and system definition of all the children devices and their special files are removed. The and options remove only those special files that are associated with the given device driver or that belong to the given device class, respectively. This is useful when there is more than one type of special file mapped to a single hardware path. These options are not supported with the class or device drivers which do not have a hardware module on the system; for example, the class. If the option is specified, the definition of all devices at that hardware path are removed from the system, again without removing any special files. The (verbose) option displays the name of each special file as it is deleted. The (quiet) option suppresses the deletion message. With the option, disables the legacy naming model, removing all legacy I/O nodes and their device special files from the system. If the and options are specified, performs an unbind on the driver associated with the given hw_path. The hw_path must be a LUN hardware path (see intro(7)). The option removes stale device special files and the stale IO nodes from the system. A specific stale hw_path can be specified with If the given node has children, all the children devices will be removed. Note that when is used, no special files will be removed. Stale device special files can be displayed using the command with option (see lssf(1M)). Note that most drivers do not support the ability to be removed from the system. If the device being removed from the system uses a dynamically assigned major number, that number will be freed up for future allocation only when used with option. Options recognizes the following options: Remove the definition of the device from the system along with all special files that refer to the device. This option cannot be used with Initiates and displays the Critical Resource Analysis (CRA) report. The (quiet) option can be used to suppress the CRA report. Also note that this option cannot be used in single user mode. Match devices that belong to a given device class, class. Device classes can be listed with the command (see lsdev(1M)). This option cannot be used with Match devices that are controlled by the specified device driver, driver. Device drivers can be listed with the command (see lsdev(1M)). This option cannot be used with Override the default device installation directory and remove the special files from directory instead. directory must exist; otherwise, displays an error message and exits. See Match devices at a given hardware path, hw-path. Hardware paths can be listed with the command (see ioscan(1M)). A hardware path specifies the addresses of the hardware components leading to a device. It consists of a string of numbers separated by periods such as (a card), (a target address), and (a device). If a hardware component is a bus converter, the following period, if any, is replaced by a slash as in and In the agile view (see intro(7)), the devices will have new hardware path formats, which can be displayed with the command (see ioscan(1M)). See section for more about using this option for critical resources. Remove the definition of the device from the system, but not any special files. This option cannot be used with Disable legacy naming model. This command removes all legacy I/O nodes and their device special files. Also this command removes legacy stale device special files found in the following directories: Therefore, before running this command, all applications should have been migrated to use the agile naming model. The command (see iofind(1M)) can be used to find all the ASCII files on the system containing legacy device file names or hardware paths. The command will not complete successfully if any legacy I/O nodes are in the open state. If this is the case, the command will fail and it will return information about the processes that opened the legacy I/O nodes, such as process name, PID, and device special file. Note: If the legacy naming model needs to be re-enabled, run (see insf(1M)). To check the current status of the legacy naming model, run Before running this command, check the latest release notes of HP-UX 11i Version 3 on for information on limitations that exist when legacy mode is disabled and how this may impact your system. This command will not validate the presence or utilization of products with these limitations. Also note that this option cannot be used in single user mode. Remove the dynamically assigned major number of the device. This option must be used with the or or option. Quiet option. Normally displays a message as each driver is removed. This option suppresses the driver message, but not error mes- sages. Unbind the driver associated with the given hardware path. The hardware path must be a LUN hardware path. This option must be used with the option. Verbose option. Prints the name of the special file as it is removed by May be used as a progress indicator. Remove all the stale IO nodes and the stale device special files from the system. These entries correspond to those nodes which have an entry in the system I/O configuration files but the corresponding device is not found (see ioconfig(4)). This option removes the stale device special files in the following directories only: Also this option removes stale device special files of interface drivers like and from the directory. Note that when is used along with no stale device special files will be removed. RETURN VALUE
exits with one of the following values: Successful completion, including warning diagnostics. Failure. An error occurred. Driver does not support this feature. DIAGNOSTICS
Most of the diagnostic messages from are self-explanatory. Listed below are some messages deserving further clarification. Errors cause to halt immediately. Warnings allow the program to continue. Errors No device in the system matched the options specified. Use to list the devices in the system (see ioscan(1M)). The file is not associated with an IO device. Warnings The H/W type of the node specified by hw_path is BUS_NEXUS/INTERFACE. All the devices under this path will be removed. The definition of the device located at hw_path and controlled by driver cannot be removed from the kernel. That is driver does not support the function. The special file does not map to a device in the system; the file is removed unless the option was specified. EXAMPLES
Remove the special file from the current directory: Remove the system definition of the device associated with along with all special files that refer to the device: Remove the system definitions for all devices associated with hardware path 52.6.0: Remove all the stale IO nodes and stale device special files from the system: Unbind a driver associated with a node corresponding to the hardware path 64000/0xfa00/0x6: WARNINGS
Most commands and subsystems assume their device files are in therefore the use of the option is discouraged. Most device drivers do not support the unbind operation necessary to remove the device from the system. Use of the command should be done carefully when it is initiated on a node with H/W type which maps to boot device or a node with H/W type to which boot device is connected as this could lead to a system hang if no mirroring Volume Group exists to the critical device. AUTHOR
was developed by HP. FILES
SEE ALSO rm(1), insf(1M), iofind(1M), ioscan(1M), lsdev(1M), lssf(1M), mksf(1M), ioconfig(4), intro(7). rmsf(1M)
All times are GMT -4. The time now is 07:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy