Urgent awk help !!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Urgent awk help !!
# 1  
Old 09-17-2009
Data Urgent awk help !!

Hi All,I need to convert following field from a file

L2578978CLC/576/116804 => L2578978CLC/00000576/00168304

i have to append Zeros in the third and fourth number after slash / in the above string (total length of number should be 8).

means L2578978CLC/576/116804 should be converted to L2578978CLC/00000576/00168304


currently i am doing it following way using awk:

Code:
_TSN2=L2578978CLC/576/116804 
split(_TSN2, a, "/") 

S2="00000000" a[2]
S3="00000000" a[3]

L2=length(S2)
L3=length(S3)
Total=8

L2=L2-Total
L3=L3-Total

S2=substr(S2,L2,Total)
S3=substr(S3,L3,Total)

_TSN2= a[1] "/" S2 "/" S3


Last edited by unknown123; 09-17-2009 at 03:58 AM..
# 2  
Old 09-17-2009
please use code tags, and dont title your post with help, need help, or something similar
# 3  
Old 09-17-2009
Code:
# echo "_TSN2=L2578978CLC/576/116804 " | awk -F/ '{printf "%s/%08d/%08d\n", $1,$2,$3}'
_TSN2=L2578978CLC/00000576/00116804

To keep the forums high quality for all users, please take the time to format your posts correctly.
  1. Use Code Tags when you post any code or data samples so others can easily read your code.
    You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
  2. Avoid adding color or different fonts and font size to your posts.
    Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
  3. Be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
Reply With Quote

Last edited by danmero; 09-17-2009 at 04:03 AM.. Reason: Add output
# 4  
Old 09-17-2009
HTML Code:
Hi,
 Many Thanks for your reply and guidelines...
 
but i want to use this converted _TNS2 variable under awk .
I want to append this variable to some other variable as follows:
 
Line=Instru "|" $11 "|" $12 "|" $18 "|" _TSN2
 
can you please let me know how can i use this modified value under same awk program?
 
thanks in advance

Last edited by unknown123; 09-17-2009 at 04:21 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Urgent help on awk/sed

Hi, Sample Input Table 1 XXXXX YYYYY A 1 2 3 4 5 B 1 2 3 4 5 C 1 2 3 4 5 D 1 2 3 4 5 A 6 7 B 6 7 C 6 7 D 6 7 Table 2 XXXXX YYYYY E 1 2 3 4 5 F 1 2 3 4 5 E 6 7 F 6 7 Table 3 XXXXX YYYYY G 1 2 3 4 5 (4 Replies)
Discussion started by: ravin
4 Replies

2. Shell Programming and Scripting

awk or sed help urgent

Hello, I have a file with the follwoing pattern: Input file: =========== tcp://xxx:123 8179 YY 1798 YY tcp://abc:2345 not found tcp://swt:4945 7356 QQ tcp://pqr:456 8178 PP 9485 PP 4485 PP (8 Replies)
Discussion started by: uandme2k2
8 Replies

3. Shell Programming and Scripting

urgent help awk script

Hi I have a scenario where i have a file name as abcd_To_hfgh.20090456778_1.dat I will get the filename as parameter and i need a string in between second _ and first . i.e i need hfgh in this case. Please help me with the script. This may not be awk script even if it can be... (2 Replies)
Discussion started by: dsdev_123
2 Replies

4. Shell Programming and Scripting

XML Awk : Urgent

Hi All, I am a beginner to Unix. So would really appreciate if people out here can help me out. I have a XML file which has a element <NoteData> in which two values DBHA and DAKO. I need to search these in all the XML files in a directory and if found in the XML file then replace the... (3 Replies)
Discussion started by: karansachdeva
3 Replies

5. UNIX for Dummies Questions & Answers

awk help urgent

Hi i am trying to read a line from a file and add the values in a new file eg Input file a1|a2|a3|a4|a5|a6 b1|b2|b3|b4|b5|b6 c1|c2|c3|c4|c5|c6 expected output File one a1|a2|a3 b1|b2|b3 c1|c2|c3 (3 Replies)
Discussion started by: rysh
3 Replies

6. Shell Programming and Scripting

Awk Doubt _ Urgent

Guys I have the file TEST.csv generated after a join of two different files with the same columns: key,string,data,number,key,string,data,number abc,test,020202,3,abc,test,010305,4 abc,level,070202,9,abc,tool,010203,7 def,tool,010101,7,,,, ghi,,,ghi,test,010203,8 I have to generate a... (2 Replies)
Discussion started by: Rafael.Buria
2 Replies

7. Shell Programming and Scripting

Urgent!!!!! AWK

Thank everyone advanced. Would you please tell me how to use the shell variable in the awk body? I try follows but they all do not work, pls kindly help me: 1. str=`cat file2` awk 'BEGIN{print("'"$str"'"}' file1 > file3 2. str=`cat file2` awk 'BEGIN{print(ENVIRON}' file1 > file3 3.... (3 Replies)
Discussion started by: summer_cherry
3 Replies

8. Shell Programming and Scripting

Urgent - Looping using AWK

Hi I have a file which is having following text. The file is in a tabular form with 5 fields. i.e field1, field2 ..... field5 are its columns and there are many rows in it say COUNT is the number of rows Field 1 Field2 Field3 Field4 Field5 ------- ------- ... (8 Replies)
Discussion started by: skyineyes
8 Replies

9. Shell Programming and Scripting

Help me for AWK URGENT

i have a record like 1,23423,4545,6767,89898,3434,121212,123123,322 2,23233,3434,4545,56566,rxrx,e344343,343434,3434 1,23223,336,78787,78787,654,6767677,6877989,7878 i want to check the $6 field if its start with any letters, i want to move this record to some other file and keep rest of... (2 Replies)
Discussion started by: readycpbala
2 Replies
Login or Register to Ask a Question