I really need help from someone who knows shell programming in Unix(sh)

I really need help from someone who knows shell programming in Unix(sh)

Post by Anj » Sun, 11 Jan 2004 09:35:33



Hello!
I would like to get help from someone who is good in Unix, shell.
If I have a file like this;
                       34jhjkh:Zlatan:sdfdsf:4353453:TDFFG
                       546ddhg:Zop?:sdfesf:4353453:TDFFG
                       345gfdg:Rudolp:dsgdgs:436364:TDFFG and on...
Then I want the result to be like this...
                       34jhjkh       sdfdsf, Zlatan
                       546ddhg       sdfesf, Zop?
                       345gfdg       dsgdgs, Rudolp
How should I do? Please help me, I really need help.
Should I use the IFS? but how? Can I do it in an another way`?
I hope someone can help me. I should call the file by writing abcd.sh
example.txt. I know what to do A little bit but then I can't get
anywhere. THANX /Anja
 
 
 

I really need help from someone who knows shell programming in Unix(sh)

Post by William Par » Sun, 11 Jan 2004 09:42:55



> Hello!
> I would like to get help from someone who is good in Unix, shell.
> If I have a file like this;
>                        34jhjkh:Zlatan:sdfdsf:4353453:TDFFG
>                        546ddhg:Zop?:sdfesf:4353453:TDFFG
>                        345gfdg:Rudolp:dsgdgs:436364:TDFFG and on...
> Then I want the result to be like this...
>                        34jhjkh       sdfdsf, Zlatan
>                        546ddhg       sdfesf, Zop?
>                        345gfdg       dsgdgs, Rudolp
> How should I do? Please help me, I really need help.
> Should I use the IFS? but how? Can I do it in an another way`?
> I hope someone can help me. I should call the file by writing abcd.sh
> example.txt. I know what to do A little bit but then I can't get
> anywhere. THANX /Anja

If there is no empty field,
    while IFS=: read a b c d; do
        echo $a $c $b
    done

If there is empty field,
    while read line; do
        a=`cut -f 1 -d : <<< "$line"`
        b=...
        c=...
        echo ...
    done

--

Linux solution for data management and processing.

 
 
 

I really need help from someone who knows shell programming in Unix(sh)

Post by Alan Conno » Sun, 11 Jan 2004 10:28:35



Quote:

> Hello!
> I would like to get help from someone who is good in Unix, shell.
> If I have a file like this;
>                        34jhjkh:Zlatan:sdfdsf:4353453:TDFFG
>                        546ddhg:Zop?:sdfesf:4353453:TDFFG
>                        345gfdg:Rudolp:dsgdgs:436364:TDFFG and on...
> Then I want the result to be like this...
>                        34jhjkh       sdfdsf, Zlatan
>                        546ddhg       sdfesf, Zop?
>                        345gfdg       dsgdgs, Rudolp

And here's yet another way:

sed -n  's/\([^:]*\)\(:\)\([^:]*\)\(:\)\([^:]*\)\(:\)\([^:].*\)\
/\1       \5, \3/p' inputfile > outputfile

AC

 
 
 

I really need help from someone who knows shell programming in Unix(sh)

Post by Ed Morto » Sun, 11 Jan 2004 12:02:05



> Hello!
> I would like to get help from someone who is good in Unix, shell.
> If I have a file like this;
>                        34jhjkh:Zlatan:sdfdsf:4353453:TDFFG
>                        546ddhg:Zop?:sdfesf:4353453:TDFFG
>                        345gfdg:Rudolp:dsgdgs:436364:TDFFG and on...
> Then I want the result to be like this...
>                        34jhjkh       sdfdsf, Zlatan
>                        546ddhg       sdfesf, Zop?
>                        345gfdg       dsgdgs, Rudolp
> How should I do? Please help me, I really need help.
> Should I use the IFS? but how? Can I do it in an another way`?
> I hope someone can help me. I should call the file by writing abcd.sh
> example.txt. I know what to do A little bit but then I can't get
> anywhere. THANX /Anja

awk -F":" '{printf "%s\t%s, %s\n",$1,$3,$2}' inputfile

Regards,

        Ed.

 
 
 

I really need help from someone who knows shell programming in Unix(sh)

Post by Alan Conno » Sun, 11 Jan 2004 12:58:36




>> Hello!
>> I would like to get help from someone who is good in Unix, shell.
>> If I have a file like this;
>>                        34jhjkh:Zlatan:sdfdsf:4353453:TDFFG
>>                        546ddhg:Zop?:sdfesf:4353453:TDFFG
>>                        345gfdg:Rudolp:dsgdgs:436364:TDFFG and on...
>> Then I want the result to be like this...
>>                        34jhjkh       sdfdsf, Zlatan
>>                        546ddhg       sdfesf, Zop?
>>                        345gfdg       dsgdgs, Rudolp
>> How should I do? Please help me, I really need help.
>> Should I use the IFS? but how? Can I do it in an another way`?
>> I hope someone can help me. I should call the file by writing abcd.sh
>> example.txt. I know what to do A little bit but then I can't get
>> anywhere. THANX /Anja

> awk -F":" '{printf "%s\t%s, %s\n",$1,$3,$2}' inputfile

> Regards,

>    Ed.

Awk's cheating :-)

"A Pattern-Matching Programming Language"

(from the TOC in OREILLY's "sed & awk" Second Edition)

For simple jobs like this, anyway.

May as well use Swyne...errrr...I mean: "Perl".

:-|

AC

 
 
 

I really need help from someone who knows shell programming in Unix(sh)

Post by Michael Heimin » Sun, 11 Jan 2004 19:23:44




> > Hello!
> > I would like to get help from someone who is good in Unix, shell.
> > If I have a file like this;
> >                        34jhjkh:Zlatan:sdfdsf:4353453:TDFFG
> >                        546ddhg:Zop?:sdfesf:4353453:TDFFG
> >                        345gfdg:Rudolp:dsgdgs:436364:TDFFG and on...
> > Then I want the result to be like this...
> >                        34jhjkh       sdfdsf, Zlatan
> >                        546ddhg       sdfesf, Zop?
> >                        345gfdg       dsgdgs, Rudolp

[..]

Quote:> awk -F":" '{printf "%s\t%s, %s\n",$1,$3,$2}' inputfile

Or:

awk -F: '{print $1"\t"$3",",$2} infile

To make awk happy:

awk 'BEGIN{FS=":"}{print $1"\t"$3",",$2}'

--
Michael Heiming

Remove +SIGNS and www. if you expect an answer, sorry for
inconvenience, but I get tons of SPAM

 
 
 

1. Need HELP with functions in SH shell programming!


Try this little script and if it doesn't work mail me back (to save bandwidth)

========= 8<  cut here
#!/bin/sh
name() {
    echo hi
name

======

This,  when  run should echo hi.  If it works,  then take it from there. :)

ttfn,
        Mike

--
_______________________________________________________________________________
 ___                    "Mickey Mouse wears a timex watch."_ ???

 C|S                    University of Toronto Computing Services

2. SAMBA and Windows '95

3. NEED HELP WITH PROGRAMMING POP3 MAIL PROGRAM TO RETRIEVE MAIL ON UNIX-TO-UNIX

4. components file not found.

5. Need help writing UNIX shell program

6. Matrox Millennium-I and XFree86

7. Anyone know where I can find UNIX shell programming plugins for SourceEdit?

8. Writing to disk on a V880 versus a E420

9. Can someone kindly help me in UNIX shell scripting for a date conversion?

10. Beginner Shell programmer needs HELP (belonged on comp.unix.shell)

11. Do someone knows a Word-Viewer for UNIX?

12. Need the benefit of the advice of someone who knows what they are doing.....

13. Urgent help needed with sh programming