Sponsored Content
Full Discussion: Help me to write the script
Top Forums Shell Programming and Scripting Help me to write the script Post 302139026 by summer_cherry on Thursday 4th of October 2007 05:49:59 AM
Old 10-04-2007
awk

HI,
To be honest, you did not give out the detail requirements. Suppose it is as follow (remember give example if possible).

input:

Code:
a:
a b c d e f g
b c d e f g h
c d e f g h i
2 b 4 d 5 f 7
b:
b c d e f g h
g d e f g h i
k e f g h i j

output:
Code:
    a     e     c
    c           4
    2           f
    g
    k

code:
Code:
cat a b >c
nawk '{
if (a=="")
        a=sprintf("%s",$1)
else
{
        if (index(a,$1)==0)
                a=sprintf("%s,%s",a,$1)
        else
        {
                a=sprintf("%s%s",substr(a,1,index(a,$1)-1),substr(a,index(a,$1)+2,length(a)-index(a,$1)-1))
        }
}
if (b=="")
        b=sprintf("%s",$2)
else
{
        if (index(b,$2)==0)
                b=sprintf("%s,%s",b,$2)
        else
                b=sprintf("%s%s",substr(b,1,index(b,$2)-1),substr(b,index(b,$2)+2,length(b)-index(b,$2)-1))
}
if (c=="")
        c=sprintf("%s",$3)
else
{
        if (index(c,$3)==0)
                c=sprintf("%s,%s",c,$3)
        else
                c=sprintf("%s%s",substr(c,1,index(c,$3)-1),substr(c,index(c,$3)+2,length(c)-index(c,$3)-1))
}
}
END{
split(a,arr,",")
split(b,brr,",")
split(c,crr,",")
for (i=1;i<=10;i++)
printf("%5s %5s %5s\n",arr[i],brr[i],crr[i])
}' c
rm c

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help! Need to write my first script

Hi Folks! I am a MacUser and am trying to learn Unix for the last few months. I will explain in detail what I am trying to do, and apreciate you help if you can teach me even if it is a single comand line inside the script. I own a small company, where I manufacture special gypsums and... (5 Replies)
Discussion started by: fundidor
5 Replies

2. AIX

How to write script for this ?

Hi All, I want to read username and lastupdate only from /etc/security/passwd and write the same data to another file: The data in /etc/security/passwd will be in this form for example: For more details : http://www.unet.univie.ac.at/aix/files/aixfiles/passwd_security.htm#A1219924 smith:... (0 Replies)
Discussion started by: me_haroon
0 Replies

3. Shell Programming and Scripting

Please write this script for me

UNIX shell script (Bourne shell syntax) called admin_script. This script is described below as a usage summary: admin_script Note: if no options are specified, a menu is displayed which allows users to perform one of the following tasks and then exit. If incorrect options are provided,... (1 Reply)
Discussion started by: nadman123
1 Replies

4. UNIX for Dummies Questions & Answers

Should I write a PERL Script or Shell Script?

Hello, I have done some BASIC shell scripting/PERL scripting before so I am familiar with the languages. I am not really sure which one would lend itself better to the application I have to write. I am required to scan the message logs for possible break in attempts. If I use shell scripting... (2 Replies)
Discussion started by: mojoman
2 Replies

5. Shell Programming and Scripting

Better way to write this script

Hi All, I have written the following script. I have just repeated some commands, and I am sure there is a more better way to do it. I hope I one of gurus here will help me make it in a better shape. Here is the script: #! /bin/sh sed -i -e "s/test2.xxx/test3.xxx/" -e "s/output2/output3/"... (2 Replies)
Discussion started by: faizlo
2 Replies

6. Shell Programming and Scripting

Script Help - Another Way To Write This

I am adapting an Open Step ping server script to Ubuntu 8.10 and one section of my script isn't working # if there are servers that just went down or came back up, notify # with high importance if ; then echo notifying of servers that are up again or just now down notify high # if there... (2 Replies)
Discussion started by: gbxfan
2 Replies

7. AIX

how to write this script?

If I need delete some disk, for i in hdisk1 hdisk2 hdisk3 hdisk4 do rmdev -dl $i done if I have more than 100 hdisks, how to write a script like that to delete them? (6 Replies)
Discussion started by: rainbow_bean
6 Replies

8. Shell Programming and Scripting

Q: How to write this script?

Hi there :rolleyes: I have a folder called backup it is path is: ~/backup Inside this folder, there are four files: ~/backup/test1.cpp ~/backup/test2.cpp ~/backup/test3.cpp ~/backup/PATHS.TXT The fourth file PATHS.TXT contains the original paths for the three files. This is the... (4 Replies)
Discussion started by: domain
4 Replies

9. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

10. Shell Programming and Scripting

Please help me to write the script

Hi All, I have written the follwing script to take the backup of the file every day along with the date. DATE=`date +%Y%m%d` export DATE cp var/hr/hr333m.txt cp var/hr/payments/hr333m_$DATE.txt The file name as follows after taking the backup. hr333m_20110630.txt Could you... (3 Replies)
Discussion started by: ajaykumarkona
3 Replies
Moose::Autobox::Array(3)				User Contributed Perl Documentation				  Moose::Autobox::Array(3)

NAME
Moose::Autobox::Array - the Array role SYNOPOSIS
use Moose::Autobox; [ 1..5 ]->isa('ARRAY'); # true [ a..z ]->does('Moose::Autobox::Array'); # true [ 0..2 ]->does('Moose::Autobox::List'); # true print "Squares: " . [ 1 .. 10 ]->map(sub { $_ * $_ })->join(', '); print [ 1, 'number' ]->sprintf('%d is the loneliest %s'); print ([ 1 .. 5 ]->any == 3) ? 'true' : 'false'; # prints 'true' DESCRIPTION
This is a role to describe operations on the Array type. METHODS
pop push ($value) shift unshift ($value) delete ($index) sprintf ($format_string) slice (@indices) flatten flatten_deep ($depth) first last Indexed implementation at ($index) put ($index, $value) exists ($index) keys values kv each each_key each_value each_n_values ($n, $callback) List implementation head tail join (?$seperator) length map (&block) grep (&block) Note that, in both the above, $_ is in scope within the code block, as well as being passed as $_[0]. As per CORE::map and CORE::grep, $_ is an alias to the list value, so can be used to modify the list, viz: use Moose::Autobox; my $foo = [1, 2, 3]; $foo->map( sub {$_++} ); print $foo->dump; yields $VAR1 = [ 2, 3, 4 ]; reverse sort (?&block) Junctions all any none one meta print say BUGS
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT. AUTHOR
Stevan Little <stevan@iinteractive.com> COPYRIGHT AND LICENSE
Copyright 2006-2008 by Infinity Interactive, Inc. <http://www.iinteractive.com> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.18.2 2013-10-27 Moose::Autobox::Array(3)
All times are GMT -4. The time now is 05:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy