Getting a string without fixed delimiters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting a string without fixed delimiters
# 1  
Old 04-20-2011
Getting a string without fixed delimiters

I have a line of text for example


aaaa bbbb cccc dddd eeee ffffff

I would need to get the cccc however bbbb could be there or not.
So whether bbbb is in the line or not I need cccc.


I was looking at either awk or sed....and trying to start at c and end until the next space.


Also the fields are not all spaced out as example..It varies.
# 2  
Old 04-20-2011
Code:
awk '{print ($2=="bbbb")?$3:$2}' file

What does "Also the fields are not all spaced out as example..It varies." mean, exactly? There may or may not be spaces, or more that one space, or "cccc" might be somewhere else on the line, or?
# 3  
Old 04-20-2011
Could you show a sample of your actual input data? Anything I write isn't likely to work since I don't know what "ccccccc" is, plus depending on what it is, that may make it very easy or very hard.
# 4  
Old 04-20-2011
The actual output is

Code:
16351711 Duplication Done 84 SLP_tor-yd-file-resources-monthly-backup 04/20/11 00:57:48 100 001:13:05 001:13:08 04/20/11 02:10:56

I need what starts with SLP until backup....but the 84 could or could not be there
# 5  
Old 04-20-2011
Yes... But will it always begin with SLP? We need some way to tell the output you want from the output you don't!

If it does, it could be as simple as egrep -o "SLP_[^ \t]+" filename
# 6  
Old 04-20-2011
Yes always SLP
egrep does not work
# 7  
Old 04-20-2011
In what way does egrep "not work"? Nondescriptive answers like that help nobody.

Try it without the \t.

If you don't have the -o option at all on your system, try:

Code:
nawk '{ for (N=2; N<=NF; N++) { if($N ~ /^SLP_/) { print $N ; break; } } }' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace string between delimiters?

Hello, I would need to replace a delimiter in a flat file using.I would like to replace the semicolon (";") but only if it was contained in a string between quotes. For example: Original flat file example: abc;abc;"abc;abc";cd;"ef;ef";abc aa;bb;"aa";cc;"ddd;eee";ff Desired output:... (9 Replies)
Discussion started by: bartleby
9 Replies

2. Shell Programming and Scripting

How to Replace string between delimiters?

Basically , i want to delete strings of a particular pattern from the flat file which is " | " pipe delimited. Below are the valid formats : 1) AAA (0) 111-111-111, AAA, BB 2) AAA (0) 111-111-1111;X, AAA, BB original flat file example : |ABC ABC XHAMK|AAA (0) 111-111-111, AAA,... (3 Replies)
Discussion started by: Ravi_007
3 Replies

3. Shell Programming and Scripting

How to parse a numeric string without any delimiters?

Hi , I have a number say 12345001 which needs to be parsed. Its a number that has no delimiters.I have to read the last three digits and then the rest of digits irrespective of the total length of the number. The digits then have to be swapped and changed to a fixed length. The fillers to be... (10 Replies)
Discussion started by: Sheel
10 Replies

4. UNIX for Dummies Questions & Answers

Delete string between delimiters with sed

Hi, I need to delete all text between "|" delimiters. The line in text file typically looks like this: 1014182| 13728 -rw-r--r-- 1 imac1 staff 7026127 2 okt 2010 |/Users/imac1/Music/iTunes/iTunes Media/Music/Various Artists/We Are the World_ U.S.A. for Africa/01 We Are the World.mp3... (2 Replies)
Discussion started by: andrejm
2 Replies

5. Shell Programming and Scripting

grep fixed string with regex

Hello, all! Maybe the title is badly formulated, you can help me with that...! I'm using the GNU grep, and I need to make sure that grep will extract only what I tell it to. I have the following regular expression: *? Well, I need to make sure I grep only a word which may start with a... (11 Replies)
Discussion started by: teresaejunior
11 Replies

6. Shell Programming and Scripting

Program to insert Delimiters at fixed locations in a file, Can you please Debug it for me??

Can someone please help?I have a file - fixed.txt----------------------------AABBBBCCCCCCDDDEEFFFFGGGGGGHHHIIJJJJKKKKKKLLL----------------------------To insert delimiters at fixed lengths of 2, 4, 6, 3, I created a file text1.txt as-------------------2463----------------------and trying to execute... (10 Replies)
Discussion started by: jd_mca
10 Replies

7. Shell Programming and Scripting

Fetch the rows with match string on a fixed lenth text file - NO delimiters

Hi I am trying to fetch the rows with match string "0000001234" Input file looks like below: 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1 09 0 XXX 0000001234 Z 1... (6 Replies)
Discussion started by: nareshk
6 Replies

8. Shell Programming and Scripting

sub-string extract between variable delimiters

I need to extract certain pieces from a string, wher delimiters may vary. For example A0 B0 C0 12345677 X0 Y0 Z0 A1-B1 C1 12345678 X1 Y0 Z0 A1/B2 C77 12345679 X2 Y0 Z0 I need to get C0 12345677 X0 C1 12345678 X1 C77 12345679 X2 I tried sed, see example below: echo 'A0 B0... (2 Replies)
Discussion started by: migurus
2 Replies

9. Shell Programming and Scripting

string deletion, variable contents, fixed delimiters

Hi, I need to mass delete the following string(s) from my files weight=100, However the '100' is variable e.g Current: ---------------- moretext=bar, weight=100, moreinfo=blah extrastuff=hi, weight=9999, extrainfo=foo Desired: ------------------ moretext=bar, moreinfo=blah... (2 Replies)
Discussion started by: rebelbuttmunch
2 Replies

10. Shell Programming and Scripting

Using sed to delete string between delimiters

Hi There! I have the following string which i need to convert to i.e. between each occurence of the delimiter ('|' in this case), i need to delete all characters from the '|' to the ':' so that |10,9:12/xxx| becomes |12/xxx| How can i do this using sed? Thanks in advance! (13 Replies)
Discussion started by: orno
13 Replies
Login or Register to Ask a Question