Sponsored Content
Top Forums Shell Programming and Scripting awk command to search based on 5 user input fields Post 303008685 by rmerrird on Tuesday 5th of December 2017 12:54:25 AM
Old 12-05-2017
Question awk command to search based on 5 user input fields

Code:
Field1=””
  Field2=””
  Field3=””
  Field4=””
  Field5=””

USER INPUT UP TO 5 FIELDS

Code:
awk -F , '{ if ( $3 == Field1 && $6 == Field2 && $8 == Field3 && $9 == Field4 && $10 == Field5) print $0 }' /tmp/rodney.outD

INPUT FILE (Rodney.outD):

Code:
prd_care_d,CARE_PD,prdensp117,CARE_PD-SCMSProcess-2017-11-11.properties,2017-11-11,SCMSProcess,129,Stream: R2017.11.11,Thu Nov 09 13:22:44 PST 2017,RUNNING,CARE_PD-SCMSProcess-2017-11-11-SCMS_Process_Archive-117A.tra,2017-11-28 19:00,,14370,11-11$
  prd_care_d,CARE_PD,prdensp117,CARE_PD-SerializationProcess-2016-11-16.properties,2016-11-16,SerializationProcess,242,Stream: R2016.11.15,Tue Nov 15 10:21:57 PST 2016,RUNNING,CARE_PD-SerializationProcess-2016-11-16-Serialization_Process_Archive-117A.tra,2017-11-28 19:00,,30765,08-09$
  prd_care_d,CARE_PD,prdensp117,CARE_PD-TugsServiceLoggerProcess-2017-11-15.properties,2017-11-15,TugsServiceLoggerProcess,14,Stream: R2017.11.14,Wed Nov 15 22:50:49 PST 2017,RUNNING,CARE_PD-TugsServiceLoggerProcess-2017-11-15-Tugs_ServiceLogger_Process_Archive-117A.tra,2017-11-28 19:00,,12369,11-16$
  prd_care_d,CARE_PD,prdensp117,CARE_PD-VestaProcess-2017-01-21.properties,2017-01-21,VestaProcess,161,Stream: R2017.01.21,Thu Jan 19 09:37:40 PST 2017,RUNNING,CARE_PD-VestaProcess-2017-01-21-Vesta_Process_Archive-117A.tra,2017-11-28 19:00,,31468,08-09$

Basically what I need is a way to front load each of the 5 fields with a value that will act like a pass thru value on my awk statement. This way I can use the same "==" operator regardless of what the user inputs.


Thanks in advance.

Last edited by jim mcnamara; 12-05-2017 at 03:03 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search file, change existing value based on input (awk help)

I have a file (status.file) of the form: valueA 3450 valueB -20 valueC -340 valueD 48 I am tailing a data.file, and need to search and modify a value in status.file...the tail is: tail -f data.file | awk '{ print $3, ($NF - $(NF-1)) }' which will produce lines that look like this: ... (3 Replies)
Discussion started by: nortonloaf
3 Replies

2. UNIX for Dummies Questions & Answers

Validating input based on fixed number of fields

Yes, i did... let me state my problem in more detail Inputs: I have one input CSV file And, i have stored no. of comma each line should in a variable. e.g. $ cat cmt.csv this, is a ,comma ,count test1 ,,this, is a ,comma ,count test2 this, is a ,comma ,count test3... (6 Replies)
Discussion started by: Dipali
6 Replies

3. Shell Programming and Scripting

Search on date range of file based on user input

Hello I would like to ask for help with a script to search a directory that contains many log files and based on a users input after being prompted, they enter a date range down to the hour which searches the files that contain that range. I dont know how to go about this. I am hoping that the... (5 Replies)
Discussion started by: lostincashe
5 Replies

4. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

5. Shell Programming and Scripting

How to preserve spaces in input fields with awk?

I'm trying to do something pretty simple but its appears more complicated than expected... I've lines in a text file, separated by the comma and that I want to output to another file, without the first field. Input file: file1,item, 12345678 file2,item, 12345678 file2,item, ... (8 Replies)
Discussion started by: Armoric
8 Replies

6. UNIX for Dummies Questions & Answers

Split files based on user input

Hi All, I have a UNIX script which reads "PxyType" (read PxyType) as input from user and a file (eg : "File.json") with the list all PxyType's. Based on the user input for "PxyType" in "File.json", I want to redirect each matched line to a different file ("File1,2,3,..json"). Can you... (7 Replies)
Discussion started by: Deena1984
7 Replies

7. Shell Programming and Scripting

Bash to search file based off user input then create new file

In the below bash a file is downloaded when the program is opened and then that file is searched based on user input and the result is written to a new file. For example, the bash is opened and the download.txt is downloaded, the user then enters the id (NA04520). The id is used to search... (5 Replies)
Discussion started by: cmccabe
5 Replies

8. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

9. Shell Programming and Scripting

Grep command to search pattern corresponding to input from user

One more question: I want to grep "COS_12_TM_4 pattern from a file look likes : "COS_12_TM_4" " ];I am taking scan_out as the input from the user. How to search "COS_12_TM_4" in the file which is corresponds to scan_out (12 Replies)
Discussion started by: Preeti Chandra
12 Replies

10. UNIX for Beginners Questions & Answers

awk to clean up input file, printing both fields

In the f1 file below I am trying to clean it up removing lines the have _tn_ in them. Next, removing the characters in $2 before the ninth /. Then I remove the ID_(digit- always 4). Finally, the charcters after and including the first _. It is curently doing most of it but the cut is removing $1... (5 Replies)
Discussion started by: cmccabe
5 Replies
CONFIG.SUB(1)							   User Commands						     CONFIG.SUB(1)

NAME
config.sub - validate and canonicalize a configuration triplet SYNOPSIS
config.sub [OPTION] CPU-MFR-OPSYS or ALIAS DESCRIPTION
Canonicalize a configuration name. Operation modes: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit REPORTING BUGS
Report bugs and patches to <config-patches@gnu.org>. COPYRIGHT
Copyright 1992-2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
autoconf(1), automake(1), autoreconf(1), autoupdate(1), autoheader(1), autoscan(1), config.guess(1), config.sub(1), ifnames(1), libtool(1). GNU Autoconf 2.69 August 2017 CONFIG.SUB(1)
All times are GMT -4. The time now is 07:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy