Sponsored Content
Top Forums Shell Programming and Scripting Print specific field when condition met Post 302950174 by znesotomayor on Wednesday 22nd of July 2015 04:19:15 AM
Old 07-22-2015
Print specific field when condition met

Hi All,

Seeking for your assistance to print all the specific field when the condition met.
Code:
Ex:
file1.txt
1|203|3|31243|5341|6452|623|22|00|01
3|45345|123214|6534|3423|6565|643|343|232|10

if field 1 = 1 and field 3 = 3 and field 5 = 5341 and field 6 = 6452
it will print from $1 to $10.

What i did was i used awk but it output first all $1 record then next is all $2 record which is wrong.

Code:
#!/bin/sh

type1=`awk -F "|" '{print $1}' file1.txt`
type2=`awk -F "|" '{print $3}' file1.txt`
type3=`awk -F "|" '{print $5}' file1.txt`
type4=`awk -F "|" '{print $6}' file1.txt`

if [[ $type1 == "1" && $type2 == "3"  && $type3 == "5341" && $type4 == "6452"  ]]; then
awk -F "|" '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10}'
fi

Please advise,

Thanks,
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

do nothing if condition is not met but not exit

Hello all, I created the below script....and it seemed to be working fine. My problem is i want the script to ignore rest of the things if my condition is not met but do not exit.... #!/bin/ksh ########################### ########################### # Set name of the listener, this... (2 Replies)
Discussion started by: abdul.irfan2
2 Replies

2. UNIX for Advanced & Expert Users

While loop only if a condition is met

All, I wrote the following section of code (which logically in PHP would of worked): tmpPATH=${1} tmpTAG=${2} if then while read tmpTAG tmpPATH do fi echo $tmpTAG echo $tmpPATH if then done < ./config.cfg fi (4 Replies)
Discussion started by: Cranie
4 Replies

3. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

4. Shell Programming and Scripting

awk to replace a specific field in certain condition

Hi, I have a file like below PRUM,67016800 ,CC ,C1,67016800 , ,Y,Y,2 ,CK,BX,FOX ,00000001,EA,00000001,20141120 00:00:00, ,N,Y,Y,CK ABCDEF... (7 Replies)
Discussion started by: mady135
7 Replies

5. Shell Programming and Scripting

Getting the records once condition met

Hi All, Seeking for your assistance to get the records once the $2 met the condition. Ex. file 1.txt 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 123232,11-Aug-2015 08:33:37 PM,4234324,1321432,34364 Output: 123455,10-Aug-2020 07:33:37 AM,2335235,1323534,12343 What i did... (5 Replies)
Discussion started by: znesotomayor
5 Replies

6. Shell Programming and Scripting

Need help on how to append on the filename when condition met.

Hi All, Seeking for your assistance on how to append the specific string when $3 condion met. ex. file1.txt ar0050046b16,5,888,0,0,0,0.00,0.00,0.00,0.00,25689.55 ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55 ar0050046b16,5,0,0,0,0,0.00,0.00,0.00,0.00,25689.55 expected output:... (5 Replies)
Discussion started by: znesotomayor
5 Replies

7. Shell Programming and Scripting

Add another condition to bash for when not met

In the below I can not seem to add a line that will add Not low if the statement in bold is not true or meet. I guess when the first if statement is true/meet then print low, otherwise print Not low in $(NF + 1). I am not sure how to correctly add this. Thank you :). if(low <= $2 && $2 <=... (5 Replies)
Discussion started by: cmccabe
5 Replies

8. UNIX for Beginners Questions & Answers

awk - print when condition is met

I have a file.txt containing the following: Query= HWI-ST863:386:C5Y8UACXX:3:2302:16454:89688 1:N:0:ACACGAAT Length=100 Score E Sequences producing significant alignments: (Bits) Value ... (2 Replies)
Discussion started by: tons92
2 Replies

9. Shell Programming and Scripting

Find line then evaluate text on next line, print when condition is met

Hello, I am looking for a specific situation in a text file. The conditions are, > <CompoundName> InChI=1S/C5H12NO2/c1-5(2)4-8-6(3)7/h5H,4H2,1-3H3/q+1 I am looking for cases where the line "> <CompoundName>" is followed by a line that contains the string "InChI=" without regard to... (5 Replies)
Discussion started by: LMHmedchem
5 Replies

10. Shell Programming and Scripting

awk to print text in field if match and range is met

In the awk below I am trying to match the value in $4 of file1 with the split value from $4 in file2. I store the value of $4 in file1 in A and the split value (using the _ for the split) in array. I then strore the value in $2 as min, the value in $3 as max, and the value in $1 as chr. If A is... (6 Replies)
Discussion started by: cmccabe
6 Replies
SENTINELLA(1)							   User Commands						     SENTINELLA(1)

NAME
sentinella - System monitor that can react to user chosen conditions SYNOPSIS
sentinella [Qt-options] [KDE-options] [options] DESCRIPTION
Action launcher based on system activity Generic options: --help Show help about options --help-qt Show Qt specific options --help-kde Show KDE specific options --help-all Show all options --author Show author information -v, --version Show version information --license Show license information -- End of options OPTIONS
-s, --start The condition will be run immediately. Condition options: --cpu <percentage> CPU load measurement. Use in combination with --during, --lower or --higher. --memory <megabytes> Memory usage in megabytes. Use in combination with --during, --lower or --higher. --network <kb> Network traffic in kilobytes/second. Use in combination with --interface, --during and --lower or --higher. --date-time <value> Current date and time condition. The format should be: YYYY-MM-DDTHH:MM:SS --program-dies <pid> The condition will be met when the process of id <pid> dies. -h, --higher The condition will be met if the system's activity is higher than your chosen value. -l, --lower The condition will be met if the system's activity is lower than your chosen value. -d, --during <time> The time during the condition must be met to throw the action. Format: MM:SS. -i, --interface <name> Sets the name of the network interface to monitor when using the --network parameter. Action options: --shutdown <force> Shutdown the computer when the condition is met. <force> values are 'yes' or 'no'. --reboot <force> Reboot the computer when the condition is met. Possible values for <force> are 'yes' or 'no'. --sleep <mode> Place computer in sleep mode when the condition is met. Possible values for <mode> are 'Standby', 'Suspend' or 'Hibernate'. --execute-command The command will be read from stdin. --terminate-program <pid> It will try to terminate the program specified by <pid>. sentinella 0.9.0-3 November 2011 SENTINELLA(1)
All times are GMT -4. The time now is 09:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy