Sponsored Content
Top Forums Shell Programming and Scripting Get output of multiple pattern match from first field to a file Post 302990456 by MadeInGermany on Thursday 26th of January 2017 12:59:37 PM
Old 01-26-2017
Code:
#!/bin/sh
pserver=""
while read server path
do
  if [ "$server" != "$pserver" ]; then
    exec 3>>"$server".out
    pserver=$server
  fi
  echo "$server $path" >&3
done < datafile.txt

If the input file is sorted, it can become more efficient
Code:
#!/bin/sh
pserver=""
sort -k1,1 datafile.txt |
while read server path
do
  if [ "$server" != "$pserver" ]; then
    exec 3>"$server".out
    pserver=$server
  fi
  echo "$server $path" >&3
done < datafile.txt

 

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
FC-MATCH(1)                                                                                                                            FC-MATCH(1)

NAME
fc-match - match available fonts SYNOPSIS
fc-match [ -asvVh ] [ --all ] [ --sort ] [ --verbose ] [ -f format | --format format ] [ --version ] [ --help ] [ pattern [ element ... ] ] DESCRIPTION
fc-match matches pattern (empty pattern by default) using the normal fontconfig matching rules to find the best font available. If --sort is given, the sorted list of best matching fonts is displayed. The --all option works like --sort except that no pruning is done on the list of fonts. If any elements are specified, only those are printed. Otherwise short file name, family, and style are printed, unless verbose output is requested. OPTIONS
This program follows the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. -a --all Displays sorted list of best matching fonts, but do not do any pruning on the list. -s --sort Displays sorted list of best matching fonts. -v --verbose Print verbose output of the whole font pattern for each match, or elements if any is provided. -f --format format Format output according to the format specifier format. -V --version Show version of the program and exit. -h --help Show summary of options. pattern Displays fonts matching pattern (uses empty pattern by default). element If set, the element property is displayed for matching fonts. SEE ALSO
fc-list(1) FcFontMatch(3) FcFontSort(3) FcPatternFormat(3) fc-cat(1) fc-cache(1) fc-pattern(1) fc-query(1) fc-scan(1) The fontconfig user's guide, in HTML format: /usr/share/doc/fontconfig/fontconfig-user.html. AUTHOR
This manual page was updated by Patrick Lam <plam@csail.mit.edu>. 16 April 2012 FC-MATCH(1)
All times are GMT -4. The time now is 03:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy