[sed] Finding and sticking the pattern to the beginning of successive lines up to the next pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [sed] Finding and sticking the pattern to the beginning of successive lines up to the next pattern
# 8  
Old 08-20-2018
a) you dropped the necessary sed -rn options.
b) drop the trailing file in the long line.
c) in s/^$/d/, there's an s and the trailing / too many.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 08-21-2018
Thank you RudiC for your support.

For clarification: - it works.

The updated script-file:

Code:
s/^$/d/
/^[a-zA-Z]/d
/[0-9]{4}(\.[0-9]{2}){2}, [[:alpha:]]+/ {h;n;}; H; x; s/\n/\t/; p; G; s/\n/\t/; s/(.*)(\t.*)\2/\1/; x;

The command:

Code:
sed -rn -f script-file file

.
# 10  
Old 08-21-2018
RudiC said
c) in s/^$/d/, there's an s and the trailing / too many.

You still have the s/^$/d/ that puts a d on empty lines. While /^$/d deletes empty lines.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed Range Pattern and 2 lines before Start Pattern

Hi all, I have been searching all over Google but I am unable to find a solution for a particular result that I am trying to achieve. Consider the following input: 1 2 3 4 5 B4Srt1--Variable-0000 B4Srt2--Variable-1111 Srt 6 7 8 9 10 End (3 Replies)
Discussion started by: y2jacky
3 Replies

2. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

3. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

4. UNIX for Dummies Questions & Answers

Finding the same pattern in three consecutive lines in several files in a directory

I know how to search for a pattern/regular expression in many files that I have in a directory. For example, by doing this: grep -Ril "News/U.S." . I can find which files contain the pattern "News/U.S." in a directory. I am unable to accomplish about how to extend this code so that it can... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

5. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

6. UNIX for Dummies Questions & Answers

Join lines on finding a pattern

I have a file with the following contents. DTP START START START DTP START DTP START DTP START I like to join the lines like this DTP START START START DTP START DTP START (2 Replies)
Discussion started by: nsuresh316
2 Replies

7. Shell Programming and Scripting

sed pattern to delete lines containing a pattern, except the first occurance

Hello sed gurus. I am using ksh on Sun and have a file created by concatenating several other files. All files contain header rows. I just need to keep the first occurrence and remove all other header rows. header for file 1111 2222 3333 header for file 1111 2222 3333 header for file... (8 Replies)
Discussion started by: gary_w
8 Replies

8. Shell Programming and Scripting

Finding lines matching the Pattern and their previous lines in a file

Hi, I am trying to locate the occurences of certain pattern like 'Possible network disconnect' in a text file. I can get the actual lines matching the pttern using: grep -w 'Possible network disconnect' file_name. But I am more interested in getting the timing of these events which are... (7 Replies)
Discussion started by: sagarparadkar
7 Replies

9. Shell Programming and Scripting

Finding Last occurance of another pattern when a pattern is found.

Hi, I have two files viz, rak1: $ cat rak1 rak2: $ cat rak2 sdiff rak1 rak2 returns: I want the lines that got modified, changed, or deleted preceding with the section they are in. I have done this so far: (1 Reply)
Discussion started by: rakeshou
1 Replies

10. Shell Programming and Scripting

grep - to exclude lines beginning with pattern

11132 13069 11137 11142 13070 Can I use grep command to exclude all lines beginning with 13? I dont want to use grep -v 13 as potentially there will be a number with something like 11013 that I would exclude in error.. (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question