![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| adding spaces for a variable value | dnat | Shell Programming and Scripting | 2 | 02-26-2008 02:32 AM |
| Adding spaces to record | nvenkat010 | Shell Programming and Scripting | 3 | 01-28-2008 10:24 AM |
| Adding an extra route to the ip routing table | Japie89 | IP Networking | 2 | 10-18-2007 04:16 PM |
| adding spaces to a line | mgirinath | Shell Programming and Scripting | 4 | 03-23-2007 09:38 AM |
| Adding Trailing Spaces to a file | 222001459 | UNIX for Dummies Questions & Answers | 1 | 11-04-2004 12:23 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
Hi all,
Thks for the advice. I think i have some idea on how to do it. However, i have another question. For eg, i have the below table, and i need to list the coordinates of every character in the table. Can any expert help ? Code:
04 D H - - 03 C G K - 02 B - L - 01 A E I - 01 02 03 04 0101 A 0102 B 0103 C 0404 D 0201 E 0202 - 0203 G 0204 H 0301 I 0302 L 0303 K 0304 - 0401 - 0402 - 0403 - 0404 - |
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
Hi try this,
Number=`tail -1 temp | wc -w` j=2 Target=`expr $Number + 1` while [ $j -le $Target ] do a[$j]=`tail -1 temp | tr -s " " | cut -d" " -f $j` j=`expr $j + 1` done Outer=2 while [ $Outer -le $Target ] do Inner=2 while [ $Inner -le $Target ] do field=`sed -n "$!/^${a[$Inner]}/p" temp | tr -s " " | cut -d" " -f $Outer` Index=${a[$Outer]}${a[$Inner]} echo "$Index $field" Inner=`expr $Inner + 1` done Outer=`expr $Outer + 1` done Thanks Penchal |
|
#10
|
|||
|
|||
|
Hi penchal_boddu,
Thks but i am using csh and awk. Do you have codes in csh or awk version ? |
|
#11
|
|||
|
|||
|
Hi All,
To make it simpler, we remove the coordinates numbers in the table but keeping in mind those are the coordinates we should be seeing. This is the input: Code:
D H - - C G K - B - L - A E I - Can any experts give some advice? Code:
{
for (x=1;x<=4;x++)
{
for (y=1;y<=4;y++)
{
#print x;
#print y;
if (NR == y ) { printf("%.2d %.2d %s\n", 5 - x, y, $y) }
}
}
}
|
|
#12
|
||||
|
||||
|
I answered you in the main thread , anyway:
Code:
sed -ne '1!G;h;$p' file|awk '{
for (i=1;i<=NF;i++)
printf("%02d%02d %s\n",i,NR,$i)
}' |sort -k1
0101 A
0102 B
0103 C
0104 D
0201 E
0202 -
0203 G
0204 H
0301 I
0302 L
0303 K
0304 -
0401 -
0402 -
0403 -
0404 -
Last edited by Klashxx; 05-16-2008 at 01:08 AM. |
|
#13
|
|||
|
|||
|
Hi,
Below is the shell to reverse a array, it means put row as column and meanwhile put column as row. Hope useful for you! input: Code:
a b c d A B C D 1 2 3 4 Code:
a A 1 b B 2 c C 3 d D 4 Code:
line=`cat file | wc -l`
nawk -v l="$line" '{
c=NF
for(i=1;i<=NF;i++)
{
t=sprintf("%s%s",NR,i)
var[t]=$i
}
}
END{
for(i=1;i<=c;i++)
{
for(j=1;j<=l;j++)
{
t=sprintf("%s%s",j,i)
printf("%s ",var[t])
}
print ""
}
}' file
|
|
#14
|
|||
|
|||
|
Quote:
What is the sed portion trying to do ? Can your code be used if the input is not a square matrix ? Pardon my ignorance as i am a novice in this area. I have devised the below code which seems to work for both square and non-square matrix. Seems that it can work. Code:
for (y=1;y<=4;y++)
{
for (x=1;x<=4;x++)
{
if (NR == y ) { printf("%.2d%.2d %s\n", x, 5 - y, $x) }
}
}
}
That' pretty useful. Thks alot!! Last edited by Raynon; 05-17-2008 at 09:34 PM. |
|||
| Google The UNIX and Linux Forums |