INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Is it easy/possible to display columns of text which is mapped from digits?

Is it easy/possible to display columns of text which is mapped from digits?

Is it easy/possible to display columns of text which is mapped from digits?

(OP)
Hi.
I'd like to write some script in shell that will display final report but will map digits to Text.
Let me explain that:
Assume I have file which is result of some operation like example:

YYMMDDHHMMSS 5 10 5 2
YYMMDDHHMMSS 6 9 4 2

Now.
You see there are 5 columns.
In colums 2-5 there is possible different digits which can have defined description in text.
Like column 2:
5 -> Text
6 -> Text1
Column 3:
10 -> Text2
9 -> Text 9
etc....

How I can than display it to have like that:
YYMMDDHHMMSS Text Text2 ... ...
YYMMDDHHMMSS Text1 Text9 ... ...

RE: Is it easy/possible to display columns of text which is mapped from digits?

Hi

Definitely possible. Probably the easiest is with Awk :

CODE --> command-line

master # cat data.txt 
YYMMDDHHMMSS 5 10 5 2
YYMMDDHHMMSS 6 9 4 2

master # cat description.txt 
2 5 -> Text
2 6 -> Text1
3 10 -> Text2
3 9 -> Text 9

master # awk -F ' *-> *' 'FNR==NR{d[$1]=$2;next}FNR==1{FS=" ";$0=$0}{for(i=2;i<=NF;i++)if(i" "$i in d)$i=d[i" "$i]}1' description.txt data.txt 
YYMMDDHHMMSS Text Text2 5 2
YYMMDDHHMMSS Text1 Text 9 4 2 
Tested with gawk and mawk.

Of course, if your descriptions are stored in other format then the one I imagined, some modifications will be needed.

Feherke.
http://feherke.github.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close