extracting a set of strings from a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extracting a set of strings from a text file
# 1  
Old 09-20-2007
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  
Old 09-20-2007
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  
Old 09-21-2007
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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting strings at various positions of text file

Hi Team - I hope everyone has been well! I export a file from one of our source systems that gives me more information than I need. The way the file outputs, I need to extract certain strings at different positions on the file and echo them to another file. I can do this in batch easily,... (2 Replies)
Discussion started by: SIMMS7400
2 Replies

2. UNIX for Dummies Questions & Answers

Extracting 22-character strings from text using sed/awk?

Here is my task, I feel sure this can be accomplished with see/awk but can't seem to figure out how. I have large flat file from which I need to extract every case of a pairing of characters (GG) in this case PLUS the previous 20 characters. The output should be a list (which I plan to make... (17 Replies)
Discussion started by: Twinklefingers
17 Replies

3. Shell Programming and Scripting

Extracting text between two strings, multiple instances

Hi experts, Ive got a text file which has the following text which will occur in this format at least one time: +=========================>> Some stuff that evreryone should knnow other stufsjdokajkajokajda aijhjajcdjajcisajcqsqdqwdqad <<=========================+ It is likely that... (8 Replies)
Discussion started by: martin0852
8 Replies

4. Shell Programming and Scripting

Extracting a set of patterns from the text file

Hi experts, I need a help in extracting a set of patterns from the text file. Below is my scenario. Input file: I need to extract the data between My output should be as Thanks, Kalai (7 Replies)
Discussion started by: kalpeer
7 Replies

5. Shell Programming and Scripting

Extracting text between two constant strings

Hi All, I have a file whose common patter is like this: .I 1 .U 87049087 .S Some text here too .M This is a text .T Some another text here .P Name of the book .W Some lines of more text. This text needs to be extracted. .A more text goes here too .I 2 (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

6. Shell Programming and Scripting

Extracting strings from a log file.

I'm new to all this and I've been fiddling with this problem for HOURS and feel silly that I can't work it out! I have a .log file that VERY long and looks like this: 2011-08-31 10:03:34 SUESTART AG Amndmnt Client WebRequest DNU SUEEND Sequence: 600, 2011-08-31 10:03:34 SUESTART... (11 Replies)
Discussion started by: SusieSA
11 Replies

7. Shell Programming and Scripting

Extracting text between two strings

Hi, I've looked at a few existing posts on this, but they don't seem to work for my inputs. I have a text file where I want to extract all the text between two strings, every time that occurs. Eg my input file is Anna said that she would fetch the bucket. Anna and Ben moved the bucket.... (9 Replies)
Discussion started by: JamesForeman
9 Replies

8. Shell Programming and Scripting

Extracting text between two strings, first instance only

There are a lot of ways to extract text from between two strings, but what if those strings occur multiple times and you only want the text from the first two strings? I can't seem to find anything to work here. I'm using sed to process the text after it's extracted, so I prefer a sed answer, but... (4 Replies)
Discussion started by: fubaya
4 Replies

9. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

10. Shell Programming and Scripting

Help with extracting strings from a file

I want to collect the characters from 1-10 and 20-30 from each line of the file and take them in a file in the following format.Can someone help me with this : string1,string2 string1,string2 string1,string2 : : : : (7 Replies)
Discussion started by: cmsdelhi
7 Replies
Login or Register to Ask a Question