Bash script to compare file all the files exits or not

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Bash script to compare file all the files exits or not
# 1  
Old 07-01-2018
Bash script to compare file all the files exits or not

Currently i am building a script like based on region parameter it will filter the records in config file and then it will create a text file like ab.txt and it will read the path location in that file and now i need to compare the files name in the config file to files in the path of the config file if the file exists it has to say file exists and list of the file that are exists if file not exists list of the files that are not exists
note: in my real time file name is going to change daily in that first three characters is only going to match

My script

Code:
#!/bin/bash

SOURCE_CONF="./test.properties"

#input region name
region="$1"
echo $region
cwd=$(pwd)
calu=$(grep $region test.properties > ab.txt)

IFS=$'\n'

#loop to read the config one line at a time
while read p; do
    echo $p

    a=($(echo "$p" | tr '|' '\n'))
    echo "Region is:" "${a[0]}"
    echo "path is:""${a[3]}"
    path="${a[3]}"
    #remove white space before path
    echo $cwd
    FOO_NO_LEAD_SPACE="$(echo -e $path | tr -d '[:space:]')"
    echo "path is:"$FOO_NO_LEAD_SPACE
# change to path spacified in the config file
    sh -c 'cd $FOO_NO_LEAD_SPACE && echo "in the subshell" && echo $pwd && echo "exit subshell" && exec pwd'
    echo $cwd
    echo "--------------------"
done < ab.txt

echo "abc"

My config file

Code:
region | Module |country code | filepath |filename


APJ | WDMD | MYS |/c/Users/vattikun/desktop | MYS*ADPGV*.XML
APJ | WDED | EUR|/c/Users/vattikun/desktop/Payroll Support | EUR*ADPGV*.XML

APJ | WDMD | RER|/c/Users/vattikun/desktop/Payroll Support | RER*ADPGV*.XML

APJ | WDJD | EYZ|/c/Users/vattikun/desktop/Payroll Support | EYZ*ADPGV*.XML


EMA | WDMD | AUS|/c/Users/vattikun/desktop | AUS*ADPGV*.XML
EMA | WDMD | AYS| /c/Users/vattikun/desktop | AYS*ADPGV*.XML

AMS | WDMD |ITI| /c/Users/vattikun/desktop | ITI*ADPGV*.XML
 AMS |WDMD |AYS| /c/Users/vattikun/desktop | AYS*ADPGV*.XML




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!
Post in adequate forum!
Seriously: start complying to forum rules!

Last edited by saranath; 07-01-2018 at 02:40 AM.. Reason: Added CODE tags & moved from "How to Post in the The UNIX and Linux Forums"
# 2  
Old 07-01-2018
Please deploy way more care when phrasing your request. WHAT do you want to achieve - in the file system, test real file existence pointed to by fields 4 and 5 of your config file? Ans attempts / ideas / thoughts from your side? In your script, there's no evidence of fulfilling above request, on top of it distorting the path names.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare date bash script

I all I have written a bash script for compare two date. One of those is a result of query, and another is current date. I have a problem with the format, because the first is 09/12/19 18:50:30 but for having this result I have to do d1DB=$(date -d "$valData" +'%m/%d/%y %T') and the second... (9 Replies)
Discussion started by: rdie77
9 Replies

2. UNIX for Beginners Questions & Answers

Script to check if files exits

Hi In live system core files are generating frequently. around 10 core files in 30 mins in root file system. which is eating my space very much below is core file core.56539 core.78886 core.12302 core.80554 core.20147 I am trying to write a script which should move... (7 Replies)
Discussion started by: scriptor
7 Replies

3. Shell Programming and Scripting

Script to compare files in 2 folders and delete the large file

Hello, my first thread here. I've been searching and fiddling around for about a week and I cannot find a solution.:confused: I have been converting all of my home videos to HEVC and sometimes the files end up smaller and sometimes they don't. I am currently comparing all the video files... (5 Replies)
Discussion started by: Josh52180
5 Replies

4. Shell Programming and Scripting

Ssh bash script exits without remote command completion

Hi, My goal is to connect from unix server A to windows server B and call a bat file on windows. I am able to succeed in remoting to windows and executing a command, the issue i am facing is the shell scrip is exiting without making sure of bat file success. Can you please help me in... (4 Replies)
Discussion started by: pxp018
4 Replies

5. Shell Programming and Scripting

Bash script to compare 2 file

Hello Friends please help me to create script to compare 2 fiile which has rpm info . File 1: glibc-2.12.1.149.el6_6.5.x86_64.rpm glibc-common-2.12-1.149.el6_6.5.x86_64.rpm File 2 : glibc-2.12.123.el6_6.5.x86_64.rpm glibc-common-2.12-123.el6_6.5.x86_64.rpm To compare file1... (1 Reply)
Discussion started by: rnary
1 Replies

6. Shell Programming and Scripting

BASH - Compare 2 Files, Output All Matches

This is probably rehash but I did look. :rolleyes: I want a bash script that will take Item 1 in File1, traverse all lines in File2 and output if a match exists. Continuing the pattern recursively, Item2, File1, traverse all lines in File2 for a match, continue this pattern until all lines... (6 Replies)
Discussion started by: rcbarr2014
6 Replies

7. Shell Programming and Scripting

Bash script to compare two lists

Hi, I do little bash scripting so sorry for my ignorance. How do I compare if the two variable not match and if they do not match run a command. I was thinking a for loop but then I need another for loop for the 2nd list and I do not think that would work as in the real world there could... (2 Replies)
Discussion started by: GermanJulian
2 Replies

8. UNIX for Advanced & Expert Users

Shell Script to compare xml files and print output to a file

All, PLease can you help me with a shell script which can compare two xml files and print the difference to a output file. I have attached one such file for you reference. <Group> <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec... (2 Replies)
Discussion started by: kanthrajgowda
2 Replies

9. Shell Programming and Scripting

Bash scripting to compare N number of files located in two directories

I want to compare "N" (around 2000+) number of huge files located in a directory A against "N" files located in a different directory using Bash scripting. Please help me with any scripts available. Thanks. (2 Replies)
Discussion started by: Sangtha
2 Replies

10. Shell Programming and Scripting

Compare entries in two files, output one of them in bash

I have two files which are of the following format: File1: Unnamed Unnamed Boston Unnamed New_York Unnamed File2: San_Francisco Chicago Portland Austin Orlando Los_Angeles In the case where an entry in File1 is "Unnamed", I want to output the name from the same line in File2.... (5 Replies)
Discussion started by: forthekill
5 Replies
Login or Register to Ask a Question