Sponsored Content
Top Forums Shell Programming and Scripting Assigning a specific format to a specific column in a text file using awk and printf Post 302417447 by goodbenito on Thursday 29th of April 2010 03:56:46 PM
Old 04-29-2010
Assigning a specific format to a specific column in a text file using awk and printf

Hi,

I have the following text file:

8 T1mapping_flip02 ok 128 108 30 1 665000-000008-000001.dcm
9 T1mapping_flip05 ok 128 108 30 1 665000-000009-000001.dcm
10 T1mapping_flip10 ok 128 108 30 1 665000-000010-000001.dcm
11 T1mapping_flip15 ok 128 108 30 1 665000-000011-000001.dcm
12 T1mapping_flip30 ok 128 108 30 1 665000-000012-000001.dcm
15 T1mapping_flip02 ok 128 108 30 1 665000-000015-000001.dcm
16 T1mapping_flip05 ok 128 108 30 1 665000-000016-000001.dcm
17 T1mapping_flip10 ok 128 108 30 1 665000-000017-000001.dcm
18 T1mapping_flip15 ok 128 108 30 1 665000-000018-000001.dcm
19 T1mapping_flip30 ok 128 108 30 1 665000-000019-000001.dcm

Using the following code, I've managed to get this far:
Code:
while read line ; 
do echo $line | awk '{print $2 "/" $1 "/" $8}' ; 
done < file

...to produce this output:

T1mapping_flip02/8/665000-000008-000001.dcm
T1mapping_flip05/9/665000-000009-000001.dcm
T1mapping_flip10/10/665000-000010-000001.dcm
T1mapping_flip15/11/665000-000011-000001.dcm
T1mapping_flip30/12/665000-000012-000001.dcm
T1mapping_flip02/15/665000-000015-000001.dcm
T1mapping_flip05/16/665000-000016-000001.dcm
T1mapping_flip10/17/665000-000017-000001.dcm
T1mapping_flip15/18/665000-000018-000001.dcm
T1mapping_flip30/19/665000-000019-000001.dcm

The problem is, I would like the middle number (field #3) to be a 3-digit number, e.g. 008, 009, 010...019.

I've tried this:

Code:
while read line ; 
do echo $line | awk '{print $2 "/" {printf "%03d\n" $1} "/" $8}' ; 
done < file

...but obviously I don't know what I'm doing because I get a big ugly syntax error.

Any help would be greatly appreciated as always.
Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert a text from a specific row into a specific column using SED or AWK

Hi, I am having trouble converting a text file. I have been working for this whole day now, still i couldn't make it. Here is how the text file looks: _______________________________________________________ DEVICE STATUS INFORMATION FOR LOCATION 1: OPER STATES: Disabled E:Enabled ... (5 Replies)
Discussion started by: Issemael
5 Replies

2. UNIX for Dummies Questions & Answers

AWK Command to find text in specific column

I'm new to scripting and would appreciate any help. I have a list of over 20 words in File1 that I need to find in columns 10-15 of File2. I need the entire row of File2 that the File1 list matches. I originally used a grep command which works, but provides File1 results that can be found... (3 Replies)
Discussion started by: Chillin
3 Replies

3. UNIX for Dummies Questions & Answers

Replacing a specific column of a text file with another column

I have a text file in the following format: 13412 NA06985 0 0 2 46.6432798439 4 4 4 4 13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4 13412 NA06993 0 0 1 45.8022601455 4 4 2 4 13401 NA06994 0 0 1 48.780669145 4 4 4 4 13401 NA07000 0 0 2 47.7312017846 2 4 4 4 13402 NA07019... (3 Replies)
Discussion started by: evelibertine
3 Replies

4. UNIX for Dummies Questions & Answers

Replacing a specific column of a text file with another column

Hi, I have a text file in the following format: Code: 13412 NA06985 0 0 2 46.6432798439 4 4 4 4 13412 NA06991 NA06993 NA06985 2 48.8478948517 4 4 2 4 13412 NA06993 0 0 1 45.8022601455 4 4 2 4 13401 NA06994 0 0 1 48.780669145 4 4 4 4 13401 NA07000 0 0 2 47.7312017846 2 4 4 4 ... (2 Replies)
Discussion started by: evelibertine
2 Replies

5. UNIX for Dummies Questions & Answers

Use sed to replace but only in a specific column of the text file

Hi, I would like to use sed to replace NA to x ('s/NA/x/g'), but only in the 5th column of the space delimited text file, nowhere else. How do I go about doing that? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

6. UNIX for Dummies Questions & Answers

Switching the values in a specific column of a text file

Hi, I have a space de-limited text file. In the fifth column, I would like to switch "1"s with "2"s. How do I go about doing that? Thanks! Sample input: 0 311000259 0 0 1 1 0 311000397 0 0 1 2 0 311000491 0 0 2 1 0 311000516 0 0 2 1 0 311000541 0 0 1 1 0 311000558 0 0 2 1 0 311000566 0... (1 Reply)
Discussion started by: evelibertine
1 Replies

7. UNIX for Dummies Questions & Answers

How to cut from a text file based on value of a specific column?

Hi, I have a tab delimited text file from which I want to cut out specific columns. If the second column equals one, I want to cut out columns 1 and 5 and 6. If the second column equals two, I want to cut out columns 1 and 5 and 7. How do I go about doing that? Thanks! (4 Replies)
Discussion started by: evelibertine
4 Replies

8. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

9. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

10. Shell Programming and Scripting

Using awk to change a specific column and in a specific row

I am trying to change the number in bold to 2400 01,000300032,193631306,190619,0640,1,80,,2/ 02,193631306,000300032,1,190618,0640,CAD,2/ I'm not sure if sed or awk is the answer. I was going to use sed and do a character count up to that point, but that column directly before 0640 might... (8 Replies)
Discussion started by: juggernautjoee
8 Replies
gdcminfo(1)							       GDCM							       gdcminfo(1)

NAME
gdcminfo - Display meta info about the input DICOM file. SYNOPSIS
gdcminfo [options] file-in DESCRIPTION
The gdcminfo command line program takes as input a DICOM file, or a directory and process it to extract meta- information about the DICOM file processed. PARAMETERS
file-in DICOM input filename options options -r --recursive recursive. -d --check-deflated check if file is proper deflated syntax. --resources-path Resources path. --md5sum Compute md5sum of Pixel Data attribute value. --check-compression check the encapsulated stream compression (lossless/lossy). general options -h --help print this help text and exit -v --version print version information and exit -V --verbose verbose mode (warning+error). -W --warning warning mode, print warning information -E --error error mode, print error information -D --debug debug mode, print debug information environment variable GDCM_RESOURCES_PATH path pointing to resources files (Part3.xml, ...) Simple usage gdcmData Using data from gdcmData: $ gdcminfo gdcmData/012345.002.050.dcm MediaStorage is 1.2.840.10008.5.1.4.1.1.4 [MR Image Storage] NumberOfDimensions: 2 Dimensions: (256,256) Origin: (-85,21.6,108.7) Spacing: (0.664062,0.664062,1.5) DirectionCosines: (1,0,0,0,0,-1) Rescale Intercept/Slope: (0,1) SamplesPerPixel :1 BitsAllocated :16 BitsStored :16 HighBit :15 PixelRepresentation:1 Orientation Label: CORONAL Davie Clunie datasets: Using data from David Clunie datasets: $ gdcminfo BRTUM001.dcm MediaStorage is 1.2.840.10008.5.1.4.1.1.4.1 [Enhanced MR Image Storage] NumberOfDimensions: 3 Dimensions: (256,256,15) Origin: (40,-105,105) Spacing: (0.820312,0.820312,6) DirectionCosines: (0,1,0,0,0,-1) Rescale Intercept/Slope: (0,1) SamplesPerPixel :1 BitsAllocated :16 BitsStored :16 HighBit :15 PixelRepresentation:1 Orientation Label: SAGITTAL Checking the md5sum of the Pixel Data After compressing a DICOM file (see gdcmconv) using a lossless compression algorithm, it is fairly easy to compare the two files for differences at DICOM attribute level. However one operation is slightly easier to do: how to make sure the compression was actually lossless ? In this case one could use the --md5sum operation. Take an uncompressed DICOM image file: $ gdcminfo --md5sum SIEMENS_ImageLocationUN.dcm The tool return: 0621954acd5815e0b4f7b65fcc6506b1 Now compress this file: $ gdcmconv --jpegls SIEMENS_ImageLocationUN.dcm lossless_compressed.dcm and then check again the md5sum: $ gdcminfo --md5sum lossless_compressed.dcm The tool return: 0621954acd5815e0b4f7b65fcc6506b1 Checking if Pixel Data is lossless In come environment one wish to check whether or not the DICOM file is lossless or not. It is fairly easy to do that in most cases. Only in two occasion this is not clear from the sole DICOM Attribute. When the Transfer Syntax is JPEG 2000 Image Compression (1.2.840.10008.1.2.4.91) and when the Transfer Syntax is JPEG-LS Lossy (Near-Lossless) Image Compression (1.2.840.10008.1.2.4.81). In this case, the only solution is to open the Pixel Data element, read the specific JPEG header and check whether or not the JPEG transformation was lossless or not: $ gdcminfo --check-compression gdcmData/MAROTECH_CT_JP2Lossy.dcm The tool returns: 'Encapsulated Stream was found to be: lossy' SEE ALSO
gdcmdump(1), gdcmraw(1), gdcmconv(1) COPYRIGHT
Copyright (c) 2006-2011 Mathieu Malaterre Version 2.2.0 Tue Feb 5 2013 gdcminfo(1)
All times are GMT -4. The time now is 08:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy