LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Shell Script Field longer than 20 characters (https://www.linuxquestions.org/questions/programming-9/shell-script-field-longer-than-20-characters-891451/)

karelvdm 07-13-2011 05:16 AM

Shell Script Field longer than 20 characters
 
Hi Guys,

I apologise if the Heading might be incomplete or misleading, but didnt know how to word it.

I can do basic to intermediate shell scripting ( I think ) but I need some LQ help with this one.

So I have a text file with about 10 000 lines. Each line containes a description of medical item. In certain cases the first 20 characters of the description is excactly the same.
Code:

WHIN HUBER NEED G20X3/4"(19MM)
WHIN HUBER NEEDLE 19X1INC
WHIN HUBER NEEDLE 20G 1/2 40MM
WHIN HUBER NEEDLE G20 1"
WINGED INFUSION CONTINUO 23G
WINGED INFUSION CONTINUO 25G
WINGED INFUSION INTERMIT 21G
WINGED INFUSION INTERMIT 23G
WINGED INFUSION INTERMIT 25G
WISE GUIDE CATHETER 7F AL2
WISE GUIDE CATHETER 7F FL4
WISE GUIDE CATHETER 7F FR4
WISE GUIDE CATHETER 7F FR5
WISE GUIDE CATHETER 7F MP1
WISE GUIDE CATHETER 7F Q3.5
WISE GUIDE CATHETER 7F Q4
WISE GUIDE CATHETER 7F VL4

The first 20 characters of one of the Descriptions would be WISE GUIDE CATHETER.
What I want to achive is to output only the descriptions where the first 20 characters are the same to a different text file.

For example, taken the Items above, WHIN HUBER NEEDLE wont be in the output file, because the first 20 characters are not the same.
But WINGED INFUSION CONTINUO, WINGED INFUSION INTERMIT,WISE GUIDE CATHETER would be in the output file.

Hope im making sense.

Karel

colucix 07-13-2011 05:45 AM

Quote:

Originally Posted by karelvdm (Post 4413604)
But WINGED INFUSION CONTINUO, WINGED INFUSION INTERMIT,WISE GUIDE CATHETER would be in the output file.

This is not clear. These strings are equal until the 16th character, not the 20th. Please, can you elaborate? And what have you tried so far and in which language (bash, awk, others...)?

Guttorm 07-13-2011 06:09 AM

Hmm. Not sure about the 16/20 thing. Are you looking for something like this?

Code:

sort textfile.txt | uniq --check-chars=20 --repeated
Output:
Quote:

WINGED INFUSION CONTINUO 23G
WINGED INFUSION INTERMIT 21G
WISE GUIDE CATHETER 7F AL2
Edit:
Or this?

Code:

sort textfile.txt | uniq --check-chars=20 --repeated --all-repeated
Output:
Quote:

WINGED INFUSION CONTINUO 23G
WINGED INFUSION CONTINUO 25G
WINGED INFUSION INTERMIT 21G
WINGED INFUSION INTERMIT 23G
WINGED INFUSION INTERMIT 25G
WISE GUIDE CATHETER 7F AL2
WISE GUIDE CATHETER 7F FL4
WISE GUIDE CATHETER 7F FR4
WISE GUIDE CATHETER 7F FR5
WISE GUIDE CATHETER 7F MP1
WISE GUIDE CATHETER 7F Q3.5
WISE GUIDE CATHETER 7F Q4
WISE GUIDE CATHETER 7F VL4

karelvdm 07-13-2011 06:24 AM

Quote:

Originally Posted by Guttorm (Post 4413637)
Code:

sort textfile.txt | uniq --check-chars=20 --repeated --all-repeated
Output:

Guttorm,

Thanx, That was what I was looking for.


All times are GMT -5. The time now is 12:47 PM.