DECODE file field is required in Bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting DECODE file field is required in Bash
# 1  
Old 02-24-2009
DECODE file field is required in Bash

Dear All,

I want to decode the one of the file field.

Input file:
9393939393|999|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01|0
9393939393|2001|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01|0
9393939393|1500|2009-02-20 00:00:01|2||4587| 2007-02-28 00:00:01|0
9393939393|999|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01| 0
9393939393|1500|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01|0

Required output file:
9393939393|MRP_25|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01|0
9393939393|MRP_75|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01|0
9393939393|MRP_50|2009-02-20 00:00:01|2||4587| 2007-02-28 00:00:01|0
9393939393|MRP_25|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01| 0
9393939393|MRP_50|2009-02-20 00:00:01|2||4587|2007-02-28 00:00:01|0


Any option is there in UNIX, to decode the field & recreate the new file with the decoded value.


Regards
Hanuma
# 2  
Old 02-24-2009
Code:
awk -F"|" '
        $2 == "999"     { sub(/.*/,"MRP-25",$2); print}
        $2 == "1500"    { sub(/.*/,"MRP-50",$2); print}
        $2 == "2001"    { sub(/.*/,"MRP-75",$2); print}
' OFS="|" infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Decode a file

hi i have this file : <?xml version="1.0" encoding="UTF-8"?> <OnDemand xmlns="http://xsd.telecomitalia.it/Schema/crmws.entity.OnDemand" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xsd.telecomitalia.it/Schema/crmws.entity.OnDemand... (2 Replies)
Discussion started by: Francesco_IT
2 Replies

2. UNIX for Beginners Questions & Answers

Assistance required to decode sed search using /1

Hi, I am trying to extract line number (first number), as well as everything from TSVal onwards. 4 1.474005 172.18.124.142 -> 74.125.228.46 TCP 2450940617 74 44021 > https Seq=0 Win=5840 Len=0 MSS=1380 SACK_PERM=1 TSval=2450940617 TSecr=0 WS=64 6 1.488149 172.18.124.142 ->... (1 Reply)
Discussion started by: sand1234
1 Replies

3. Windows & DOS: Issues & Discussions

Decode windows .dat file

I have received a file from a Windows server that in Linux hexedit shows the following first few characters. AA 18 3C 2B 60 56 03 00 00 01 01 00 The Windows program may have received this via RS232. I need to "understand" this on a Linux machine. Please suggest where I may start decoding... (4 Replies)
Discussion started by: Alf Stockton
4 Replies

4. Shell Programming and Scripting

Bash interactive Script Required

Dear All, Please help in creating a bash script to fetch records from multiple files the script should ask inputs of file type and column level input(at least 4 col of each file type) I have 4 sort of Files, A,B,C,D. file names are like A_0112.unl, A_01215.unl, A_0001.unl and same with B C... (3 Replies)
Discussion started by: Muhammad Ali
3 Replies

5. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

6. Shell Programming and Scripting

Bash file 1 and file then add field

Hi All, Seeking for your assistance regarding on how to bash file 1 and file 2 then add the field if the bash is true. Ex. nik1.csv - input file 1 1,0054,0001,4,5,6,7,May 1,USA 11,0053,0002,14,15,16,17,May 2,PHL 40,0052,0003,43,44,45,46,May 5,GER nik2.csv - input file 2... (11 Replies)
Discussion started by: nikki1200
11 Replies

7. UNIX for Advanced & Expert Users

How to decode nfs file handle in HP-UX?

Hi Experts, Any idea how to decode file handle in HP-UX? I am getting the following error continously in my HP-UX 11.31 box :mad: Apr 26 07:15:00 host62 su: + tty?? root-bb Apr 26 07:15:00 host62 su: + tty?? root-abcadm Apr 26 07:15:01 host62 vmunix: NFS write error on host peq9vs:... (1 Reply)
Discussion started by: vipinable
1 Replies

8. Shell Programming and Scripting

How to filter required data from file using bash script?

Hi All , I have one file like below , Owner name = abu2-kxy-m29.hegen.app Item_id = AX1981, special_id = *NULL*, version = 1 Created = 09/01/2010 12:56:56 (1283389016) Enddate = 03/31/2011 00:00:00 (1301554800) From the above file I need to get the output in the below format ,i need... (3 Replies)
Discussion started by: gnanasekar_beem
3 Replies

9. UNIX for Dummies Questions & Answers

Help required on printing the line if third field is not a empty space

Hi Experts, I want to print the lines whose third field in non-empty/blank space. i.e. INPUT FILE/B] dcdccghjrry0yd cont dcdccttrk820529 cont rdekedfsSCr dcdccttrdky2d0y cont rdekedfsSC2 ... (3 Replies)
Discussion started by: krao
3 Replies

10. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies
Login or Register to Ask a Question