need Script logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need Script logic
# 1  
Old 01-03-2011
need Script logic

Hi, i have a file called sc.txt
Code:
cat sc.txt
ecf0183.sh
ecf1002.sh
ecf1011.sh
ecf1020.sh

another file callled All.csv
Code:
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

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


Moderator's Comments:
Mod Comment Please use code tags when posting data and code samples!

Last edited by Franklin52; 01-03-2011 at 04:36 AM..
# 2  
Old 01-03-2011
Assuming the two files are sorted:
Code:
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.
# 3  
Old 01-03-2011
Code:
# ./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

Code:
 ## 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

# 4  
Old 04-14-2011
File permissin issue

How can i get the permission of the files in a directory if we dont have access to the directory.
# 5  
Old 04-14-2011
Quote:
Originally Posted by JSKOBS
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.
# 6  
Old 04-14-2011
Code:
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

# 7  
Old 04-15-2011
hi ygemici, can u plz explain me how to executable on a dir
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need script logic

i have two csv files (rates.csv, reference.csv) as below. rates.csv contains Code, respective Zone details rates.csv ---------- 23,38Nhava 45,37NEWYORK 89,SHILANG 71,ROBACCA reference.csv contains all Zone details reference.csv ------------- 37Newyork robacca 38Nhava... (5 Replies)
Discussion started by: p_satyambabu
5 Replies

2. Shell Programming and Scripting

Script logic

Please help me to write the following script. 1) Input files will be in Test directory. (Test/YYYY/MM) folders (Ex: 1) 2010/ 01 2) 2011/05) The file name will be Testfile1_6676543218_Axxxxxxyyyyyzzzzzzzzzzzzzzzzzz.pdf.gz 2) The compare file will be in /tmp directory. (/tmp/comparefile.txt). The... (6 Replies)
Discussion started by: mnjx
6 Replies
Login or Register to Ask a Question