Login or Register to Ask a Question and Join Our Community


Sorting content between match pattern and move on with awk and sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting content between match pattern and move on with awk and sed
# 1  
Old 07-25-2014
Sorting content between match pattern and move on with awk and sed

Code:
S 0.0 0.0 (reg, inst050)
k
e
f
d
c

S 0.0 0.0 (mux, m030)
k
g
r
s
x
v

S 0.0 0.0 (reg, inst020)
q
s
n
m

S 0.0 0.0 (rpt13, rpt13)
p
e
m
a
x
z
l
t
f
g

S 0.0 0.0 (INPUT)
t
g
h
w
d

can i have an ideal on 2 cases with sed/awk by sorting the content between S 0.0 and empty space
# 2  
Old 07-25-2014
Please post the expected output.
# 3  
Old 07-25-2014
thanks. the output results should look like this
Code:
S 0.0 0.0 (reg, inst050)
c
d
e
f
k

S 0.0 0.0 (mux, m030)
g
k
r
s
v
x

S 0.0 0.0 (reg, inst020)
m
n
q
s


S 0.0 0.0 (rpt13, rpt13)
a
e
f
g
l
m
p
t
x
z

S 0.0 0.0 (INPUT)
d
g
h
t
w

# 4  
Old 07-25-2014
And why do you need two cases with sed and awk?

Is this a homework assignment?

What have you tried so far?
# 5  
Old 07-25-2014
i had anther post 6 hrs ago with different question, and the solution was with sed. that is the reason i would stay with sed for my solution but in this example, the resources i could find was mostly with awk.
Print lines between two patterns , the awk way

i asked because it could help me in my daily task. not school assignment.
# 6  
Old 07-25-2014
Try
Code:
awk 'NF==1 {print | "sort"} NF!=1 {close ("sort"); print}' file

This User Gave Thanks to RudiC For This Post:
# 7  
Old 07-25-2014
hi Rudic
that is very powerful single line solution, would you mind to explain to me how it actually does?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get range out using sed or awk, only if given pattern match

Input: START OS:: UNIX Release: xxx Version: xxx END START OS:: LINUX Release: xxx Version: xxx END START OS:: Windows Release: xxx Version: xxx ENDHere i am trying to get all the information between START and END, only if i could match OS Type. I can get all the data between the... (3 Replies)
Discussion started by: Dharmaraja
3 Replies

2. Shell Programming and Scripting

awk command to get file content until 2 occurrence of pattern match

AWK command to get file content until 3 occurrence of pattern match, INPUT FILE: JMS_BODY_FIELD:JMSText = <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <custOptIn xmlns="http://com/walm/ta/cu/ccs/xml2"> <person>Romi</person> <appName>SAP</appName> </custOptIn> ... (4 Replies)
Discussion started by: prince1987
4 Replies

3. Shell Programming and Scripting

Pattern match with awk/sed - help

I need to grep for the pattern text inside the square brackets which are in red and not in green..my current code greps patterns both of them, which i don't want Input fileref|XP_002371341.1| oxoacyl-ACP reductase, putative gb|EPT24759.1| 3-ketoacyl-(acyl-carrier-protein) reductase ... (2 Replies)
Discussion started by: selvankj
2 Replies

4. Shell Programming and Scripting

sed : match one pattern then the next consecutive second pattern not working

Ive used this snippet of code on a solaris box thousands of times. But it isnt working on the new linux box sed -n '/interface LoopBack0/{N;/ ip address /p;}' *.conf its driving me nuts !! Is there something Im missing ? (7 Replies)
Discussion started by: popeye
7 Replies

5. Shell Programming and Scripting

Awk-sed help : to remove first and last line with pattern match:

awk , sed Experts, I want to remove first and last line after pattern match "vg" : I am trying : # sed '1d;$d' works fine , but where the last line is not having vg entry it is deleting one line of data. - So it should check for the pattern vg if present , then it should delete the line ,... (5 Replies)
Discussion started by: rveri
5 Replies

6. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

7. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

8. Shell Programming and Scripting

Match a pattern starting with sub-pattern using sed

Hi all, I've been experiencing a difficulty trying to match a number and write it to a new file. My input file is: input.txt It contains the lines: 103P 123587.256971 3.21472112 3.1517423 1.05897234566427 58.2146258 12.35478 25.3612489 What would be the sed command to... (17 Replies)
Discussion started by: Biederman
17 Replies

9. Shell Programming and Scripting

awk/sed/perl command to delete specific pattern and content above it...

Hi, Below is my input file: Data: 1 Length: 20 Got result. Data: 2 Length: 30 No result. Data: 3 Length: 20 (7 Replies)
Discussion started by: edge_diners
7 Replies

10. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies
Login or Register to Ask a Question

Featured Tech Videos