output words between sentences SED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting output words between sentences SED
# 1  
Old 12-16-2008
output words between sentences SED

Hi, i need to delete every thing ecept sentences between known prases lets say
i have

Code:
Thu Dec  4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)

i need information between
Code:
Login OK: [

and
Code:
] (from

what is vyce6220. between
Code:
 client

and
Code:
port

between
Code:
cli

and
Code:
)

what is 001644fc4838

so the output should be :
vyce6220 LINKSYS3 001644fc4838

i have tried
Code:
sed 's#.*Login OK: [\(.*\)] (.*#\1#' radoms.txt

but it doesn't work because of [ but i need login name whithout them and the secon thing is that i can't make more betweens to find
# 2  
Old 12-16-2008
Code:
# awk -F 'start' 'BEGIN{RS="end"; OFS="\n"; ORS=""} {print $2}' test.txt
or
# sed -n '/^start/,/^end/{/LABEL$/!p}' test.txt

# 3  
Old 12-16-2008
Quote:
Originally Posted by Ikon
Code:
# awk -F 'start' 'BEGIN{RS="end"; OFS="\n"; ORS=""} {print $2}' test.txt
or
# sed -n '/^start/,/^end/{/LABEL$/!p}' test.txt

ok i understand start and end but what is LABEL$ and !p ?
# 4  
Old 12-16-2008
Hi,

choose one of two ways:

Code:
sed 's/.*OK: \[\([^]]*\).*/\1/' <<< \
"Thu Dec  4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"

or much easier:

Code:
IFS="[]" && read 1 2 3 <<< \
"Thu Dec  4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"
echo $2

HTH Chris
# 5  
Old 12-16-2008
Quote:
Originally Posted by wrwe
ok i understand start and end but what is LABEL$ and !p ?
Just leave those as is, just change start and end
# 6  
Old 12-16-2008
Quote:
Originally Posted by Christoph Spohr
Hi,

choose one of two ways:

Code:
sed 's/.*OK: \[\([^]]*\).*/\1/' <<< \
"Thu Dec  4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"

or much easier:

Code:
IFS="[]" && read 1 2 3 <<< \
"Thu Dec  4 08:28:57 2008 : Auth: Login OK: [vyce6220] (from client LINKSYS3 port 12 cli 001644fc4838)"
echo $2

HTH Chris
thanks it works good, but i need complex comand of that i dont understand how to do that. taht you can look between word and word2 and also at the same command between word3 and word4.
# 7  
Old 12-16-2008
Quote:
Originally Posted by Ikon
Just leave those as is, just change start and end
first whith !p:

Code:
p: Event not found.

whithout !p

Code:
: command } expects up to 0 address(es), found 1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reverse words with sed

Hi guys, I'm wondering what the best way would be to reverse words in a string based on certain characters. For example: echo Word1Word2Word3Word4 | sed ' /\n/ !G s/\(Word.\)\(.*\n\)/&\2\1/ //D ' This returns: Word4Word3Word2Word1 I'm no sed expert but... (2 Replies)
Discussion started by: Subbeh
2 Replies

2. Shell Programming and Scripting

Count lines and words of a stream output with tail

Hello, I need to tail -f a file output stream and I need to get only lines that contains "get" and "point" in the same line. It doesn't matter the order. Then I need only the text BEFORE "point". I have to count each line and perform other serveral actions after this has performed 3 times.... (9 Replies)
Discussion started by: Kibou
9 Replies

3. Shell Programming and Scripting

Swap words using sed

Hi. I have to swap the first and the third word in all lines of a txt file using sed. Separators between words are: any charachter, except intervall. I hope, you'll understand what I want to do. my english is not so good, sorry for that:) (10 Replies)
Discussion started by: T720
10 Replies

4. Shell Programming and Scripting

Grep words with spaces and save the output

I have a file that contains the schedule for a tournament with 41 teams. The team names have spaces in them. I would like to search for each teams schedule and then save that to that teams file For example Team name: "Team Two" I would like to search for all the games for "Team Two" and... (8 Replies)
Discussion started by: knijjar
8 Replies

5. Shell Programming and Scripting

grep words from output file

Hi, By using shell scripit i have save output in one file. I want to grep two words named CLUSTER and CLUSQMGR from that output file. How to grep that. output file would be having below words TYPE(QCLUSTER) ALTDATE(2010-05-17) CLUSTER(QS.CL.MFT1) ... (5 Replies)
Discussion started by: darling
5 Replies

6. Shell Programming and Scripting

SED - delete words between two possible words

Hi all, I want to make an script using sed that removes everything between 'begin' (including the line that has it) and 'end1' or 'end2', not removing this line. Let me paste an 2 examples: anything before any string begin few lines of content end1 anything after anything before any... (4 Replies)
Discussion started by: meuser
4 Replies

7. UNIX for Dummies Questions & Answers

How do I color some words in output?

OK, let's say if we want to filter lines in man and get a different color for the word we are searching we write man find | grep print It will mark all the words containing print red and output only those lines containing it, let's say I want to see the complete manual, but with marked words... (1 Reply)
Discussion started by: arcelivez
1 Replies

8. Shell Programming and Scripting

sed append words

Hi all, I have a file like one two three for five six seven eight ..... Actually i need to append a label to the words that belong to the 2 column and get: one two_label three for five six_label seven eight .... I was trying with sed inside vim but I can't figure out... (9 Replies)
Discussion started by: Dedalus
9 Replies

9. Shell Programming and Scripting

search two words in sed

I've following sed command working fine - sed '/search_pattern1/ !s/pattern1/pattern2/" file Now, I want to search two patterns - search_pattern1 and search_pattern2 . How can put these into above sed statement ? Thanks in advance. (12 Replies)
Discussion started by: ajitkumar2
12 Replies

10. UNIX for Dummies Questions & Answers

sed [delete everything between two words]

Hi, I have the following codes below that aims to delete every words between two pattern word. Say I have the files To delete every word between WISH_LIST=" and " I used the below codes (but its not working): #!/bin/sh sed ' /WISH_LIST=\"/ { N /\n.*\"/ {... (3 Replies)
Discussion started by: Orbix
3 Replies
Login or Register to Ask a Question