PERL & KSH Big Question


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers PERL & KSH Big Question
# 1  
Old 05-27-2005
PERL & KSH Big Question

Hi All,
Anyhelp on the following is highly appreciated

I have a flat file which contains entrys like this


L1 I1 B1 R1
L2 I2,I3 B1 R2
L3 I1 x R3
L4 x B2 R1
L5 I2 B1 R4

x means no entry


Now after reading the file and processing the file I need hashes like this.

I1 ==>> L1,L3
I2 ==>> L5
I3 ==>> L2
I4 ==>> L2

B1 ==>> L1,L5
B2 ==>> L2,L4

R1 ==>> L1,L4
R2 ==>> L2
R3 ==>> L3
R4 ==>> L5

It can be in PERL or Kshell with minimal number of lines. Please help.

Thanks,
Jingi
# 2  
Old 06-01-2005
Can this be done using any shell commands? Please help me. Thx
# 3  
Old 06-02-2005
Got a solution .. Smilie

Code:
#! /bin/sh
for key in I B R
do
 for length in 1 2 3 4 5
 do
  LineNo= 
  HASH=
   while read line
   do
     if [[ $line = *${key}${length}* ]] ; then
      LineNo=${LineNo}" "`echo $line | awk -F" " '{ print $1 }'`
     fi;
   done < entry.txt
  HASH=${key}${length}" "${LineNo}
  echo "--"$HASH
  echo $HASH >> entry.txt.output
done
done

entry.txt is your sample input flat file.
Iterations in key and length depend on the different hash key and values.

And the output file looks like

Code:
I1 L1 L3
I2 L2 L5
I3 L2
I4
I5
B1 L1 L2 L5
B2 L4
B3
B4
B5
R1 L1 L4
R2 L2
R3 L3
R4 L5
R5

Cheers !
Vino
# 4  
Old 06-02-2005
It seems like your input and the desired output don't jive together OR I don't understand what's desired [in which case a more detailed explanation is needed].

But based on my understanding.....

nawk -f jingi.awk jingi.txt
here's jingi.awk
Code:
{
   for(i=2; i <= NF; i++)
      arr[$i] = ( $i in arr) ? arr[$i] "," $1 : $1
}
END {
  for( i in arr)
    printf("%s ==>> %s\n", i, arr[i])
}

 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies

2. Shell Programming and Scripting

combination between || and && in IF condition with ksh

Dear All, Please advice about this issue. when i run this line in a script if && || && || && if i enter $x = test3 and $y = test1 the If condition apply while it should not Best Regards (2 Replies)
Discussion started by: islam.said
2 Replies

3. Shell Programming and Scripting

Find & Replace string in multiple files & folders using perl

find . -type f -name "*.sql" -print|xargs perl -i -pe 's/pattern/replaced/g' this is simple logic to find and replace in multiple files & folders Hope this helps. Thanks Zaheer (0 Replies)
Discussion started by: Zaheer.mic
0 Replies

4. Shell Programming and Scripting

perl help to split big verilog file into smaller ones for each module

Hi I have a big verilog file with multiple modules. Each module begin with the code word 'module <module-name>(ports,...)' and end with the 'endmodule' keyword. Could you please suggest the best way to split each of these modules into multiple files? Thank you for the help. Example of... (7 Replies)
Discussion started by: return_user
7 Replies

5. Shell Programming and Scripting

perl newbie . &&..programming newbie (question 2)

Hello everyone, I am having to do a lot of perl scripting these days and I am learning a lot. I have this problem I want to move files from a folder and all its sub folders to one parent folder, they are all .gz files.. there is folder1\folder2\*.gz and there are about 50 folders... (1 Reply)
Discussion started by: xytiz
1 Replies

6. Shell Programming and Scripting

Perl or awk/egrep from big files??

Hi experts. In one thread i have asked you how to grep the string from the below sample file- Unfortunately the script did not gave proper output (it missed many strings). It happened may be i did gave you the proper contents of the file That was the script- "$ perl -00nle'print join... (13 Replies)
Discussion started by: thepurple
13 Replies

7. Shell Programming and Scripting

Perl conversion & perldoc question

Working my way through a perl book and can't find this; You can convert from binary to ordinal numbers using 0b in front of the binary value but how do you go the other way, from ordinal to binary? Is there a function for this? On Perldoc, is there a document that gives all of the available... (2 Replies)
Discussion started by: thumper
2 Replies
Login or Register to Ask a Question