pcdok
August 16, 2013, 5:16pm
1
Hello,
i wondering if anybody can help me with the following:
doing a search for the words "Sample ID:" in a file called test.txt
and I need to have the string after this (Postmatch)
Then I want that the string is used to rename an other file called test.pdf into .... the string.pdf
I already tried some thing but still with errors
awk '/Sample ID:/ { printf "mv test.pdf $3.pdf\n" ,$3,$3 >>"sampleID.txt
The following is working:
awk '/Sample ID:/ { print $3 }' sampleID.txt
and is printing the correct string that I need
If you think it is easier to do it in perl or python, I am fine with this as well to learn/adapt.
Many thanks for all your help
Kindly regards
Koen
Show some sample input please.
pcdok
August 16, 2013, 5:24pm
3
Hello,
First of all thanks for the very quick reply, here is an extract of the SampleID.txt file:
LIEGE
Name: XXXXXX
ID: 123456789
Gender: F
Sample ID: 123456789A1
Sample Type: Serum
Dilution Factor: 1
Priority: Routine
I think you can do something lke
awk '/Sample ID/ { print "echo mv test.pdf "$3".pdf"); }' sampleid.txt | sh
Remove the echo once you're sure it does what you want.
pcdok
August 16, 2013, 5:39pm
5
Thanks a lot,
We are almost there, the only minor thing is that the script is putting an ? before .pdf
110715516102?.pdf instead of 110715516102.pdf
Thanks,
Koen
Your file is full of carriage returns, probably generated by MS Windows.
awk '/Sample ID/ { sub(/\r/,""); print "echo mv test.pdf "$3".pdf"); }' sampleid.txt | sh
1 Like
pcdok
August 16, 2013, 6:01pm
7
Thanks a lot
You made my script working..
Last and simple question,
Can I add multiple codes with awk in the same bash ?
Reason for asking is that I will have different lookups ?
THANKS !!!
Koen
I don't understand the question. If you showed the input you have and the output you wanted from it, that would be very helpful.
pcdok
August 16, 2013, 6:11pm
9
It is okay like this,
I need to thank you very much for the quick answers..
My script is working now..
Kindly regards
Koen