need Script logic

Hi, i have a file called sc.txt

cat sc.txt
ecf0183.sh
ecf1002.sh
ecf1011.sh
ecf1020.sh

another file callled All.csv

Type,S Name,Mem Lib,S Id,S Table,App,Group
Reg sch,ecf1002,Link from 1,pcor1,EER,ecf1002.sh,ECF-D-LND-AMZ-A
Reg sch,ecf1002a,Link from 2,pcor1,EER,ecf1002.sh,ECF-D-LND-AX-A
Reg sch,ecf1011ab,Link from 4,pcor1,EER,ecf1011.sh,EW-G-LND-AX-A
Reg sch,ecf1020rt,Link from 9,pcor1,EER,ecf1020.sh,EW-G-JYD-GEX-D

i need to take the sc.txt as a reference and need to compare with All.csv and then need to create a file as below. please help me with the code

sc              S Name   S id   Group
ecf0183.sh 
ecf1002.sh ecf1002    pcor1 ECF-D-LND-AMZ-A
                ecf1002a  pcor1 ECF-D-LND-AX-A
ecf1011.sh ecf1011ab pcor1 EW-G-LND-AX-A
ecf1020.sh ecf1020rt  pcor1 EW-G-JYD-GEX-D

Assuming the two files are sorted:

join -e '' -a 1 -a 2 -t, -1 1 -2 6 --nocheck-order firstfile secondfile \
| awk -F, '
  BEGIN { OFS = "\t"; print "headerline"; }
  {
    if ($1 == p) { $1 = ""; } else { $1 = $1; }
    p = $1;
    print;
  }'

$1 = $1 causes awk to re-evaluate $0, inserting OFS between each field.

# ./justdoit
sc         S Name     S Id      Group
ecf0183.sh
ecf1002.sh ecf1002    pcor1 ECF-D-LND-AMZ-A
           ecf1002a   pcor1 ECF-D-LND-AX-A
ecf1011.sh ecf1011ab  pcor1 EW-G-LND-AX-A
ecf1020.sh ecf1020rt  pcor1 EW-G-JYD-GEX-D
 ## justdoit ##
#!/bin/bash
sed -n '1s/[^,]*,\([^,]*\),[^,]*,\([^,]*\),[^,]*,[^,]*,\([^,]*\)/sc\t   \1     \2\t\3/p' All.csv >results
for i in `sed "" sc.txt`
 do
   if [[ `sed -n "/$i/p" All.csv` == $'\0'  ]]; then sed -i '$ a\'$i'' results; fi ;
     sed -n "/$i/p" All.csv | sed 's/[^,]*,\([^,]*\),[^,]*,\([^,]*\),[^,]*,[^,]*,\([^,]*\)/'$i' \1 \2 \3/' |
     awk '{ printf ("%s %-10s %-5s %s\n", $1,$2,$3,$4)}' >>results
 done
sed 'N;s/\(.*\) \(.*\)\n\1 \(.*\)/\1 \2\n\t   \3/' results

How can i get the permission of the files in a directory if we dont have access to the directory.

you have to executable perm on directory at least if you know file names.

awk 'NR==FNR{a[$6]=(a[$6]=="")?$2 OFS $4 OFS $NF:a[$6] RS OFS OFS $2 OFS $4 OFS $NF;next} 
   {print $1,($1 in a)?a[$1]:X}' FS=, OFS="\t" All.csv sc.txt

ecf0183.sh
ecf1002.sh      ecf1002 pcor1   ECF-D-LND-AMZ-A
                ecf1002a        pcor1   ECF-D-LND-AX-A
ecf1011.sh      ecf1011ab       pcor1   EW-G-LND-AX-A
ecf1020.sh      ecf1020rt       pcor1   EW-G-JYD-GEX-D

hi ygemici, can u plz explain me how to executable on a dir

hi JSKOBS
this issue may has many scenarios.

you can look from this :slight_smile:
Unix File and Directory Permissions and Modes

regards
ygemici