The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replacing strings with text from other file mc1392 Shell Programming and Scripting 1 03-24-2008 11:46 AM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-09-2007 11:25 PM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 07:27 AM
Help with extracting strings from a file cmsdelhi Shell Programming and Scripting 7 01-12-2007 05:49 AM
Extracting strings hugow UNIX for Dummies Questions & Answers 1 06-24-2005 03:09 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-20-2007
Registered User
 

Join Date: May 2007
Posts: 25
Question extracting a set of strings from a text file

i have textfiles that contain a series of lines that look like this:

string0 .................................................... column3a column4a
string1**384y0439 ..................................... column3b column4b
string2**23903990 ..................................... column3c column4c
string3 .................................................. column3d column4d
string4**67823678 ..................................... column3e column4e

can you help me write a C-shell script that will list all the unique strings before the ** ?
if a string is not followed by ** (eg. string0 and string3), the string should be in the list, whether or not it is unique.
I think I need to first filter out the lines without .................................. (which are always at the beginning and end part of the textfile).

can anyone help me with this please?
thanks a lot!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-20-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,491
few people here can write C shell - here's awk & grep
Code:
awk -F'*'  '{print $1}' myfile | grep '*' | sort -u > unique
grep -v '*' myfile | sort >> unique
I hope redirection works the same in csh as everywhere else....
Reply With Quote
  #3 (permalink)  
Old 09-20-2007
Registered User
 

Join Date: May 2007
Posts: 25
thanks jim! the code was a big help and i especially like the sorted output!

my problem is now reduced to the following:
1. how can i exclude the lines without "..................................." (the first 5 lines and last 2 lines in the file)
2. for lines with strings in the first column that are not suffixed by " ** ", how can i keep the rest of the line from being displayed? (only the string in the first column should be displayed)

does anyone have any ideas?
thank you!
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0