Extract 4 digit characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract 4 digit characters
# 1  
Old 12-19-2012
Extract 4 digit characters

HTML Code:
* hdisk99          U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140BA00000000  IBM MPIO FC 1750
* hdisk100         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140BB00000000  IBM MPIO FC 1750
* hdisk185         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140A000000000  IBM MPIO FC 1750
* hdisk186         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140A100000000  IBM MPIO FC 1750
* hdisk101         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140C300000000  IBM MPIO FC 1750
* hdisk102         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140C400000000  IBM MPIO FC 1750
* hdisk103         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140C500000000  IBM MPIO FC 1750
* hdisk104         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140C600000000  IBM MPIO FC 1750
* hdisk105         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140C700000000  IBM MPIO FC 1750
* hdisk106         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140C800000000  IBM MPIO FC 1750
* hdisk107         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140C900000000  IBM MPIO FC 1750
* hdisk108         U5791.001.9920BZ4-P1-C05-T1-W500507630E060C14-L401140CA00000000  IBM MPIO FC 1750
...
From the lists above, I need to pull out the first column and 4 characters from the block starting with L (i.e. L401140BA00000000).

The outputs need to be:

HTML Code:
hdisk99 11BA
PHP Code:
11BA 
comes from L401140BA00000000
L40XX40YY......., so XXYY is the one.

For this
PHP Code:
hdisk100  L401140BB00000000 
,
it is
PHP Code:
hdisk100  11BB 
because L401140BB00000000.

Please advise.
# 2  
Old 12-19-2012
Try

Code:
awk '{n=split($3,P,"-");print $2,substr(P[n],4,2)""substr(P[n],8,2)}' file

This User Gave Thanks to pamu For This Post:
# 3  
Old 12-19-2012
Really appreciate it! Working perfect!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract characters from a string name

Hi All, I am trying to extract only characters from a string value eg: abcdedg1234.cnf How can I extract only characters abcdedg and assign to a variable. Please help. Thanks (2 Replies)
Discussion started by: abhi_123
2 Replies

2. Shell Programming and Scripting

awk to extract digit in line of text and create link

I am trying to extract the number in bold (leading zero removed) after Medexome_xx_numbertoextractin file and create an output using that extracted number. In the output the on thing that will change is the number the other test is static and will be the same each time. Thank you :). file ... (8 Replies)
Discussion started by: cmccabe
8 Replies

3. Shell Programming and Scripting

convert two digit in to single digit...

Hi Guys. My Input: ABCD 12 00 KL ABCD 12 08 DL ABCD 12 10 KK ABCD 12 04 LL ABCD 13 00 LP ABCD 13 1O LS Output: ABCD 12 0 KL ABCD 12 8 DL ABCD 12 10 KK ABCD 12 4 LL ABCD 13 0 LP (2 Replies)
Discussion started by: pareshkp
2 Replies

4. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

5. Shell Programming and Scripting

extract last 8 characters from a file name

Dear gurus I have several files with the following format filenameCCYYMMDD , that is the last 8 characters will be the date in CCYYMMDD format. eg FILENAME20110523 . Could anyone please put me through on how to extract only the last 8 characters from the files. I am thinking of using awk,sed... (2 Replies)
Discussion started by: erinlomo
2 Replies

6. UNIX for Dummies Questions & Answers

extract characters from a variable

Hi All, I have scenario as below, I want to cut the characters and store it variable2.. and want to display the variable2.. as shown below... eg: the size may differs , i am show just an example..... numbers are not fixed in variable1..i want to extract characters and... (1 Reply)
Discussion started by: G.K.K
1 Replies

7. UNIX for Dummies Questions & Answers

Replacing digit with characters in a file

Hi, I have a file with 40 columns out of which 15 are amount fields. There are approximately 6 mn records in this file. The file has data in following format: 123A,Ank,00.468,US,IL,780,53489 253A,Tng,-00.456,US,CA,452,46781 363A,nkk,-00.023,US,NJ,539,09625 I need to take all amount fields... (1 Reply)
Discussion started by: wahi80
1 Replies

8. Shell Programming and Scripting

Extract string between two different characters

I want to extract a string from a line in a text file between two different characters: for example: :string" I want to extract string. It has to be done in a one-liner. (11 Replies)
Discussion started by: rein
11 Replies

9. Shell Programming and Scripting

Replace one digit by two digit using sed

Folks, Is there a simple way to replace one digit by two digit using sed. Example, mydigit1918_2006_8_8_lag1.csv should be mydigit1918_2006_08_08_lag01.csv. I tried this way, but doesn't work. echo mydigit1989_2006_8_8_lag1.csv|sed 's/]/0]/' Thank you, (5 Replies)
Discussion started by: Jae
5 Replies

10. Shell Programming and Scripting

SED to extract characters

Hi, Please let me know how do we write a piece of code to extract characters from a line using SED. (1 Reply)
Discussion started by: Shilpi
1 Replies
Login or Register to Ask a Question