The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 03:46 PM
Extracting data from text file based on configuration set in config file suparnbector Shell Programming and Scripting 3 08-10-2007 02:25 AM
Extracting the lines between 2 strings of a file babloo Shell Programming and Scripting 2 02-14-2007 11:27 AM
Help with extracting strings from a file cmsdelhi Shell Programming and Scripting 7 01-12-2007 09:49 AM
Extracting strings hugow UNIX for Dummies Questions & Answers 1 06-24-2005 06:09 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-20-2007
Deanne Deanne is offline
Registered User
  
 

Join Date: May 2007
Posts: 31
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!
  #2 (permalink)  
Old 09-20-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
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....
  #3 (permalink)  
Old 09-20-2007
Deanne Deanne is offline
Registered User
  
 

Join Date: May 2007
Posts: 31
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!
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0