Comparing two strings receiving form two different loops and execute if condition when single match


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing two strings receiving form two different loops and execute if condition when single match
# 1  
Old 11-14-2013
Linux Comparing two strings receiving form two different loops and execute if condition when single match

I want to read a file contain sub-string and same string need to match in file name I got from for loop. I am using below code:
Code:
#!/bin/bash
C_UPLOADEDSUFFIX='.uploaded'
files=$(find . -iname '*'$C_UPLOADEDSUFFIX -type f)  # find files having .uploaded prefix
for file in $files
do
 CHK_FILE=$(basename $file)
     while read -r line; do
                  set -f          # disable globbing
 
          if [[ $CHK_FILE =~ "${line}*" ]]
 
          then
 
                  uploader()
          else
                  trap()
          fi
 
  done < FILE_NAME.txt
done

in this code if match found in if statement then uploader() run else trap() run, so it always goes to else part unnecessarily each time if condition fails.
I want, if condition " [[ $CHK_FILE =~ "${line}*" ]]” first check for all strings in FILE_NAME.txt one by one and if at least single match found then it must execute uploader() else execute trap().

Code:
FILE_NAME.txt---->
Blacklist
Customer
languages
Nationality


Last edited by vbe; 11-14-2013 at 05:23 AM.. Reason: more tags + rm fancy fonts
# 2  
Old 11-14-2013
Try using grep:

Code:
if grep -q $line $CHK_FILE ; then ... ; fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies

2. Shell Programming and Scripting

Match child with parents and form matrix

thank you for letting me join this forum, lots of learning opportunities looks like. Myself a biologist, very new into unix, so please excuse if I use incorrect language. I am using cygwin on windows, it can run perl, awk , sed etc. I have 2 files, the first sample sheet, tells which parent... (10 Replies)
Discussion started by: jalaj841
10 Replies

3. Programming

C++ for loops in a single line

I am wondering whether I can write for loops in the following ways for (int i = 0; i < NL; i++) L->read_param(P, i + 1); for (int k = 0; k < lay; k++) sum += L->get_npar(); for (int i = 0; i < NL; i++) L = new Layer(Xi, Xf); for (int i = 0; i < NL; i++) { for (int j = 0; j < NL; j++)... (3 Replies)
Discussion started by: kristinu
3 Replies

4. UNIX for Advanced & Expert Users

need to get single column form csv file

hi 2 all i need to get single column from one csv file anyone help me ! >cat file.csv name,age x,1 y,2 z,3 Use code tags please, ty. in this "file.csv" file i need only name column can u help me !:b::b: (7 Replies)
Discussion started by: ponmuthu
7 Replies

5. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

6. Shell Programming and Scripting

form a line with strings

hi i have a file with the content like TL1330000000800 000DE9147157200 08000TS0228DE91 71572AMEX0000.T N 0080000000 00000. TL1330000000500 000DE9147157200 08000TS0228DE91 71572AMEX0000.T N 0080000000 00000. i need to write like including the spaces ... (4 Replies)
Discussion started by: Satyak
4 Replies

7. Shell Programming and Scripting

comparing 2 strings

hi i have 2 strings. i want to compare the strings. please help (2 Replies)
Discussion started by: satish@123
2 Replies

8. Shell Programming and Scripting

Comparing Two Strings

Hi All, While I am trying to run below code I Am getting the exception like ./abs.sh: line 102: syntax error near unexpected token `then' ./abs.sh: line 102: ` then' The Code Snippet is: if then cat $file1 | sed -e... (8 Replies)
Discussion started by: Anji
8 Replies

9. UNIX for Advanced & Expert Users

Comparing strings

I have two strings a=Mar22 b=may21 how can I compare them Is this fine if then; . ... else .... fi or if then (2 Replies)
Discussion started by: yakyaj
2 Replies

10. Shell Programming and Scripting

comparing two strings

Hi How do i compare two strings in shell script. Below is an example but I am not getting the desired output, plz help if then echo success fi I am not getting the desired output if I do this. plz help (24 Replies)
Discussion started by: ragha81
24 Replies
Login or Register to Ask a Question