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
gdcmscu(1)							       GDCM								gdcmscu(1)

NAME
gdcmscu - Tool to execute a DICOM Query/Retrieve operation SYNOPSIS
gdcmscu [OPTION]...[OPERATION]...HOSTNAME...[PORT]... Execute a DICOM Q/R operation to HOSTNAME, using port PORT (104 when not specified) DESCRIPTION
The gdcmscu command line program is the tool to execute DICOM Query/Retrieve operation. It supports: o C-ECHO (SCU) o C-FIND (SCU) o C-STORE (SCU) o C-MOVE (SCU/SCP) C-MOVE operation are executed using two different ports (one for the SCU and one for the SCP). PARAMETERS
options options -H --hostname Hostname. -p --port Port number. --aetitle Set calling AE Title. --call Set called AE Title. mode options --echo C-ECHO (default when none). --store C-STORE. --find C-FIND. --move C-MOVE. C-STORE options -i --input DICOM filename -r --recursive recursively process (sub-)directories --store-query Store constructed query in file C-FIND/C-MOVE options --patientroot C-FIND Patient Root Model. --studyroot C-FIND Study Root Model. --patient C-FIND Query on Patient Info (cannot be used with --studyroot). --study C-FIND Query on Study Info. --series C-FIND Query on Series Info. --image C-FIND Query on Image Info. --key 0123,4567=VALUE for specifying search criteria (wildcard allowed) With --key, leave blank (ie, --key 10,10="") to retrieve values C-MOVE options -o --output DICOM filename / directory --port-scp Port for incoming associations --key 0123,4567=VALUE for specifying search criteria (wildcard not allowed) Note that C-MOVE supports the same queries as C-FIND, but no wildcards are allowed 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 --queryhelp print query help environment variable GDCM_ROOT_UID Root UID C-ECHO usage gdcmscu is a great tool to test if a DICOM server is up. For example to send a C-ECHO to server dicom.example.com using port 104, use: $ gdcmscu dicom.example.com or if you prefer being explicit: $ gdcmscu --echo dicom.example.com 104 Using basic security your DICOM server might require that you set the appropriate called AE-TITLE $ gdcmscu --echo dicom.example.com 11112 --call SERVSCP If you want to specifiy your own AE-TITLE (default is GDCMSCU), simply use: $ gdcmscu --echo dicom.example.com 11112 --call SERVSCP --aetitle MYSCU For example you could test on the DICOM server provided by DICOMObject team: $ gdcmscu www.dicomserver.co.uk 11112 C-STORE usage C-STORE is the operation that allow sending a DICOM file to a remote DICOM server. For instance to send a file called myfile.dcm $ gdcmscu --store dicom.example.com 104 myfile.dcm or if you prefer being explicit: $ gdcmscu --store dicom.example.com 104 -i myfile.dcm You can even send multiple files using the same association: $ gdcmscu --store dicom.example.com 104 myfile1.dcm myfile2.dcm myfile3.dcm ... C-FIND usage gdcmscu also allow querying a DICOM server. This is the C-FIND operation, for example to find all DICOM Instance where PatientsName match a particular pattern, usage is simply: $ gdcmscu --find --patient dicom.example.com 11112 --patientroot --key 10,10,"A*" We also support a DCMTK compatible convention: $ gdcmscu --find --patient dicom.example.com 11112 --patientroot --key 10,10="A*" When an attribute is set without a value it will be part of the output result: $ gdcmscu --find --patient dicom.example.com 11112 --call MI2B2 --patientroot -k 10,10="A*" -k 10,20 C-MOVE usage C-MOVE is the operation to retrieve a DICOM instance from a remote DICOM server. Most of the time, it is a subsequent operation after a C- FIND query. To retrieve a DICOM instance where PatientID is ABCD1234, simply execute: $ gdcmscu --move --patient --aetitle ACME1 --call ACME_STORE dicom.example.com 5678 --patientroot -k 10,20="ABCD1234" --port-scp 1234 WARNING For this operation to work you need information from the DICOM server you are communicating with. Only the DICOM server you are sending a C-MOVE query will be reponsible for sending back incoming associations (the actual C-STORE SCP). Therefore you need to make sure that you mapping of (AE-TITLE,PortNumber) is properly set on the DICOM server side as well as the port for incoming association (--port- scp). gdcmscu does not currently support external C-STORE association (C-STORE request sent to an external SCP application). patientroot notes The flag --patientroot is just simply a wrapper around the syntax --key 8,52=PATIENT For instance one would write using DCMTK syntax: findscu --patient dicom.example.com 11112 --key 8,52=PATIENT --key 10,10="F*" This would become using GDCM syntax: $ gdcmscu --find --patient dicom.example.com 11112 --patientroot --key 10,10="F*" Debugging This is sometime difficult to investigate why a connection to a remote DICOM server cannot be done. Some recommendations follows: Always try to do a simple C-ECHO at first. If you cannot get the C-ECHO to work none of the other operations will work Before trying to a C-MOVE operation, make sure you can execute the C-FIND equivalent query first. When doing a C-MOVE operation you really need to communicate with the PACS admin as the C-MOVE operation is different from the other lower level operation such as HTTP/GET. When doing a C-MOVE, the server will communicate back using another chanel (could be different port) using it's internal database to map an AE-TITLE back to the destination IP. Indeed the C-MOVE operation by design does not always use your incoming IP adress to send back the resulting dataset. Instead it uses a mapping of AE-TITLE to IP adress to send back any results. So pay particular attention to the spelling of your AE-TITLE and your incoming port (which may be different from the port to connect to the server). Port Warning Watch out that port ranging [1-1024] are reserved for admin and not easily accessible unless granted special priviliges. Therefore the default 104 DICOM port might be accessible to all your users. C-STORE Warnings When constructing a C-STORE operation, gdcmscu will always use the Media Storage as found in the file to be sent. For encapsulated DICOM file (eg. RLE Lossless) the receiving SCP server might not support this compression and will legitemely refuse the C-STORE operation. In this case users have to manually convert to a non-compressed form this particular file: $ gdcmconv --raw compressed.dcm non_compressed.dcm C-MOVE Warnings At the moment gdcmscu only supports non-compressed transfer syntax. It will always request DataSet using Implicit VR Little Endian Transfer Syntax during a C-MOVE operation. C-FIND IMAGE level (Composite Object Instance) One should pay attention that gdcmscu --find and findscu are not completely equivalent. Using gdcmscu --find, all Unique Keys will be added automatically. One can therefore execute something like this: $ gdcmscu --find --patientroot --image --key 8,18=1.2.3.4.5.6 dicom.example.com 11112 instead of the more explicit form $ gdcmscu --find --patientroot --image --key 8,18=1.2.3.4.5.6 dicom.example.com 11112 --key 10,20 --key 20,d --key 20,e This would also be equivalent to: $ findscu --patient --key 8,52=IMAGE --key 8,18=1.2.3.4.5.6 dicom.example.com 11112 --key 10,20 --key 20,d --key 20,e Storing the Query It is also possible to store the query: gdcmscu --find --patient --patientroot dicom.example.com 11112 --key 10,20="*" --key 10,10 --store-query query.dcm One can then check the DataSet values send for the query: $ gdcmdump query.dcm # Dicom-File-Format # Dicom-Meta-Information-Header # Used TransferSyntax: # Dicom-Data-Set # Used TransferSyntax: 1.2.840.10008.1.2 (0008,0005) ?? (CS) [ISO_IR 192] # 10,1-n Specific Character Set (0008,0052) ?? (CS) [PATIENT ] # 8,1 Query/Retrieve Level (0010,0010) ?? (PN) (no value) # 0,1 Patient's Name (0010,0020) ?? (LO) [* ] # 2,1 Patient ID The Specific Character Set was set to 'ISO_IR 192' as the locale encoding of the system was found automatically by gdcmscu to be UTF-8. This means that the following command line will properly setup the Query with the appropriate Charset to be executed correctly: $ gdcmscu --find --patient --patientroot dicom.example.com 11112 --key 10,10="*Jerome*" the query is always executed on the server side (SCP), some implementations does not support string matching with different Character Set. SEE ALSO
gdcmconv(1) COPYRIGHT
Copyright Insight Software Consortium Version 2.2.0 Tue Feb 5 2013 gdcmscu(1)
All times are GMT -4. The time now is 01:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy