Sponsored Content
Top Forums Shell Programming and Scripting Get output of multiple pattern match from first field to a file Post 302990453 by rveri on Thursday 26th of January 2017 12:27:04 PM
Old 01-26-2017
Get output of multiple pattern match from first field to a file

Hi All,
Greetings!

I have a file of 40000+ lines with different entries, I need matching entries filterd out to their files based on first filed pattern for the matching :

For example:
All server1 entries (in field1) to come together with its path in 2nd field.

The best output I want to have it should generate filename for each:
Say server1.out file: which would be having "first field" and "second filed" of server1.
And so on for all the serverX .


Code:
datafile.txt  : 

server1	/usr/file1
server1 /usr/fileA
server2 /usr1/fileB
server2	/usr2/fileca
server3 /usr/DB/fileA
server3 /usr1/fileA
serverA /usr1/data1
server1 /usr3/data2
server2 /usr2/data2
server2 /path1/data2
serverA /pathb/data3

Code:
Desired output to be with each filename :


server1.out
server1	/usr/file1
server1 /usr/fileA
server1 /usr3/data2


Code:
File: server2.out 

server2 /usr1/fileB
server2 /usr2/filec
server2 /usr2/data2

Code:
File: server3.out 
server3 /usr/DB/fileA
server3 /usr1/fileA


Code:
File: serverA.out
serverA /usr1/data1
serverA /pathb/data3


Thanks ..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Output Multiple Field from dataBase file

I am fairly new in unix I was wondering if anybody can help me out with this: I am trying to output to a file the following fields; Field1 Field2 Field4 From a database file dataBase1. this is how the file looks: dataBase1 TABLE DATA Example ================== Table ... (3 Replies)
Discussion started by: Dennz
3 Replies

2. Shell Programming and Scripting

how do i pattern match a field with awk?

hi, let's say $numbers = "324 350 587" an so on... what i'm trying to do is this: awk -v numbers="$numbers" '{if (numbers ~ /$2/) print $0, "bla bla"}' file # file looks like this: 214 ..... 215 ... 216 .... 250 ... 324 325 ... 350 something ... ... 587 ... (4 Replies)
Discussion started by: someone123
4 Replies

3. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

4. UNIX for Dummies Questions & Answers

Match pattern in a field, print pattern only instead of the entire field

Hi ! I have a tab-delimited file, file.tab: Column1 Column2 Column3 aaaaaaaaaa bbtomatoesbbbbbb cccccccccc ddddddddd eeeeappleseeeeeeeee ffffffffffffff ggggggggg hhhhhhtomatoeshhh iiiiiiiiiiiiiiii ... (18 Replies)
Discussion started by: lucasvs
18 Replies

5. Shell Programming and Scripting

Multiple pattern match and print the output in a single line

I need to match two patterns in a log file and need to get the next line of the one of the pattern (out of two patterns) that is matched, finally need to print these three values in a single line. Sample Log: 2013/06/11 14:29:04 <0999> (725102) Processing batch 02_1231324 2013/06/11... (4 Replies)
Discussion started by: rpm120
4 Replies

6. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

7. Shell Programming and Scripting

Remove multiple lines that match pattern

Not sure how I can accomplish this. I would like to remove all interfaces that have the commands I would like to see: switchport port-security, spanning-tree portfast. One line is no problem. interface FastEthernet0/8 spanning-tree portfast interface FastEthernet0/9 spanning-tree... (4 Replies)
Discussion started by: mrlayance
4 Replies

8. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

9. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies
bootparams(4)							   File Formats 						     bootparams(4)

NAME
bootparams - boot parameter data base SYNOPSIS
/etc/bootparams DESCRIPTION
The bootparams file contains a list of client entries that diskless clients use for booting. Diskless booting clients retrieve this infor- mation by issuing requests to a server running the rpc.bootparamd(1M) program. The bootparams file may be used in conjunction with or in place of other sources for the bootparams information. See nsswitch.conf(4). For each client the file contains an entry with the client's name and a list of boot parameter values for that client. Each entry has the form: clientname keyword=value... The first item of each entry is the host name of the diskless client. You can use the asterisk ('*') character as a "wildcard" in place of the client name in a single entry. A wildcard entry applies to all clients for which there is not an entry that specifically names them. In a given entry, the host name or asterisk is followed by one or more whitespace characters and a series of keyword--value pairs separated by whitespace characters. There must not be any whitespace within a keyword--value pair. Each keyword--value pair has the syntax: keyword=value The preceding form breaks out further as: keyword=server:value Where server can be null and value can be a pathname. An example that includes a server is: client1 root=server1:/export/client1/root An example where server is null is: client1 rootopts=:vers2 A minor variation of the keyword=value syntax is used for the domain keyword. Unlike the forms shown above, this syntax does not use a colon. For example: client1 domain=bldg1.workco.com Entries can span multiple lines. Use the backslash ('') character as the last character of a line to continue the entry to the following line. For multiple-line entries, you can split a line only in places where whitespace is allowed. For example, you can use a backslash to split the following entry between the end of the path (root) and the keyword domain: client1 root=server1:/export/client1/root domain=bldg1.workco.com In entries that specify a server, server is the name of the server that will provide the file or filesystem to the diskless client and value is the pathname of the exported file or filesystem on that server. In entries that use the domain keyword, the domain name specified must be the client's domain name. The algorithm for determining a client's domain name is to first check for a domain keyword in the client-specific entry and then in "wildcard" entry. If none is found, the server's domain name is used. For the JumpStart installation of machines that do not have video displays, use the term keyword to identify the terminal type of the boot server. Terminal types are listed in /usr/share/lib/terminfo (see terminfo(4)). An entry with the ns keyword associates a server (a name server) with, instead of a pathname, a specific name service (NIS+, NIS, LDAP, or none) and, if that server is not on a local subnet, the netmask needed to reach it. For example: ns=hoot:nisplus(255.255.255.0) An ns entry forces sysidtool(1M) to use the specified name service. By default, sysidtool uses NIS+ in preference to NIS or LDAP if it can find an NIS+ server for the system's domain on the subnet. An ns entry might be necessary if you are trying to set up a hands-off installa- tion, or if the name server is on a different subnet, which is common with NIS+. If an ns keyword is not used, sysidtool uses broadcast to attempt to bind to either a NIS+, NIS, or LDAP server. If a name server is not on the local subnet, which is possible for NIS+ or LDAP, the bind will fail, automatic configuration of the name service will fail, and an interactive screen is displayed, prompting the user to specify the name service. The ns keyword can be set in add_install_client or by Host Manager. EXAMPLES
Example 1 Sample bootparams Entry Here is an example of an entry in the bootparams file: client1 root=server1:/export/client1/root rootopts=:vers=2 domain=bldg1.workco.com client2 root=server2:/export/client2/root ns=:nis client3 root=server2:/export/client3/root ns=watson: client4 root=server2:/export/client4/root ns=mach:nisplus(255.255.255.0) Example 2 Sample Entry for JumpStart The following is an example of an entry that might be used for the JumpStart installation of diskless clients that do not have displays. mozart root=haydn:/export/install/sparc/os/latest/Solaris_9/boot install=haydn:/export/install/sparc/os/8.1/latest boottype=:in install_config=haydn:/usr/local/share/lib/jump-net ns=otis:nisplus(255.255.255.0) term=:xterms domain=eu.cte.work.com FILES
/etc/bootparams SEE ALSO
rpc.bootparamd(1M), sysidtool(1M), nsswitch.conf(4) NOTES
Solaris diskless clients use the keywords root and rootopts to look up the pathname for the root filesystem and the mount options for the root filesystem, respectively. These are the only keywords meaningful for diskless booting clients. See mount_ufs(1M). SunOS 5.11 22 Jul 2004 bootparams(4)
All times are GMT -4. The time now is 01:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy