Sponsored Content
Top Forums Shell Programming and Scripting [sed] Finding and sticking the pattern to the beginning of successive lines up to the next pattern Post 303021894 by father_7 on Monday 20th of August 2018 06:01:44 AM
Old 08-20-2018
[sed] Finding and sticking the pattern to the beginning of successive lines up to the next pattern

I have a file like below.

Code:
2018.07.01, Sunday
09:27 some text 123456789 0 21 0.06 0.07 0.00
2018.07.02, Monday
09:31 some text 123456789 1 41 0.26 0.32 0.00
09:39 some text 456789012 1 0.07 0.09 0.09
09:45 some text 932469494 1 55 0.29 0.36 0.00
16:49 some text 123456789 0 48 0.12 0.15 0.00
20:13 some text 123456789 0 46 0.12 0.15 0.00

I want the sed command to find the pattern YYYY.MM.DD, Day of week (Y-year, M-month, D-Day, e.g. 2018.07.01, Sunday) and:

  1. to copy the pattern to the buffer
  2. to remove the pattern from the given line and then
  3. to past the pattern into the line below so that you get the effect below


Code:
2018.07.01, Sunday 9:27 am some text 123456789 0 21 0.06 0.07 0.00
2018.07.02, Monday 9:31 some text 123456789 1 41 0.26 0.32 0.00
2018.07.02, Monday 09:39 some text 456789012 1 0.07 0.09 0.09
2018.07.02, Monday 9:45 some text 932469494 1 55 0,29 0,36 0,00
2018.07.02, Monday 16:49 some text 123456789 0 48 0.12 0.15 0.00
2018.07.02, Monday 20:13 some text 123456789 0 46 0.12 0.15 0.00

I will be grateful for constructive answers.

Last edited by father_7; 08-20-2018 at 07:10 AM.. Reason: small language mistakes repeired
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
PKEYPARAM(1SSL) 						      OpenSSL							   PKEYPARAM(1SSL)

NAME
openssl-pkeyparam, pkeyparam - public key algorithm parameter processing tool SYNOPSIS
openssl pkeyparam [-help] [-in filename] [-out filename] [-text] [-noout] [-engine id] [-check] DESCRIPTION
The pkeyparam command processes public key algorithm parameters. They can be checked for correctness and their components printed out. OPTIONS
-help Print out a usage message. -in filename This specifies the input filename to read parameters from or standard input if this option is not specified. -out filename This specifies the output filename to write parameters to or standard output if this option is not specified. -text Prints out the parameters in plain text in addition to the encoded version. -noout Do not output the encoded version of the parameters. -engine id Specifying an engine (by its unique id string) will cause pkeyparam to attempt to obtain a functional reference to the specified engine, thus initialising it if needed. The engine will then be set as the default for all available algorithms. -check This option checks the correctness of parameters. EXAMPLE
Print out text version of parameters: openssl pkeyparam -in param.pem -text NOTES
There are no -inform or -outform options for this command because only PEM format is supported because the key type is determined by the PEM headers. SEE ALSO
genpkey(1), rsa(1), pkcs8(1), dsa(1), genrsa(1), gendsa(1) COPYRIGHT
Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved. Licensed under the OpenSSL license (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>. 1.1.1a 2018-12-18 PKEYPARAM(1SSL)
All times are GMT -4. The time now is 11:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy