LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2011, 05:16 AM   #1
karelvdm
Member
 
Registered: Sep 2004
Location: Pietermaritzburg South Africa
Distribution: Home:OpenSuse 11, Office:FreeBSD 7 PBX:Trixbox 2 (CentOS 4.4) Home Automation : LinuxMCE
Posts: 123

Rep: Reputation: 15
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
 
Old 07-13-2011, 05:45 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by karelvdm View Post
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...)?
 
Old 07-13-2011, 06:09 AM   #3
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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

Last edited by Guttorm; 07-13-2011 at 06:13 AM.
 
1 members found this post helpful.
Old 07-13-2011, 06:24 AM   #4
karelvdm
Member
 
Registered: Sep 2004
Location: Pietermaritzburg South Africa
Distribution: Home:OpenSuse 11, Office:FreeBSD 7 PBX:Trixbox 2 (CentOS 4.4) Home Automation : LinuxMCE
Posts: 123

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Guttorm View Post
Code:
sort textfile.txt | uniq --check-chars=20 --repeated --all-repeated
Output:
Guttorm,

Thanx, That was what I was looking for.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to handle file names with space characters in a shell script? Sammy_G Programming 14 04-27-2009 10:40 AM
replaced variable field within shell script using sed hamimi Linux - Newbie 2 05-28-2008 08:01 AM
shell script question: automatic \ of escape characters in string lagu2653 Programming 2 03-08-2006 07:58 AM
shell script question: removing a line according to a duplicate "field" mattie_linux Linux - Newbie 1 01-12-2006 03:57 PM
exploding string into individual characters using a shell script farmerjoe Programming 9 10-13-2004 03:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration