Sponsored Content
Full Discussion: Join lines using sed or awk
Top Forums Shell Programming and Scripting Join lines using sed or awk Post 302983818 by greet_sed on Monday 17th of October 2016 02:51:42 PM
Old 10-17-2016
IMO, above sed solutions will give wrong results if input has LINE3 in place of LINE1 or LINE2 for example.

Below one should work for given input patterns:
Code:
sed -ne '/PATTERN/ {N;/LINE1/N;/LINE2/s/\n//gp}' file


Last edited by greet_sed; 10-17-2016 at 03:52 PM.. Reason: Add text
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk Join multiple lines

Hi, I have data with broken lines: Sample data: "12"|"25"|"a"|"b"|"c"|"d"|"e"|"f"|"2453748"|"08:10:50" "16"|"25"|"a"|"b"|"c"|"d"|"e"|"f"|" 2453748"|"08:15:50" "16"|"25"|"a"|"b"|" c"|"d"|"e"|"f"|"2453748"|"08:19:50" "16"|"25"|"a"|"b"|"c"|"d"|"e"|"f"|"2453748"|"08:19:50" In the... (5 Replies)
Discussion started by: hitmansilentass
5 Replies

2. Shell Programming and Scripting

to join the corresponding lines using shell commands or awk

Suppose u have this file gi_1 ABCDEFDHIJ KMNOPQRSTU VWXYZABCDE gi_2 JKLMNOPQRS TUVWXYZABC DEFGHIJKLM gi_3 PQRSTUVWXY ZABCDEFGHI JKLMNOPQRS gi_4 CDEFGHIJKL MNOPQRSTUV WXYZABCDEF gi_5 IJKLMNOPQR STUVWXYZAB CDEFGHIJKLM FGHIJKLMNO PQRSTUVWXY ZABCDEFABC NOPQRSTUVW XYZABCDEFG... (7 Replies)
Discussion started by: cdfd123
7 Replies

3. Shell Programming and Scripting

awk, join or sed

$ cat file1 a:23:43 A B C a:24:21 a:23:44 S D A F a:24:44 a:23:45 S D E a:24:45 $ cat file2 a:23:53 (1 Reply)
Discussion started by: jkl_jkl
1 Replies

4. Shell Programming and Scripting

Fixed Width Join & Pad Sed/Awk Help

I was wondering someone might be able to push me in the right direction, I am writing a script to modify fixed-width spool files, As you can see below the original spool file broke a single line into two for printability sake. I have had been able do the joins using sed, the thing I am... (10 Replies)
Discussion started by: Cho Nagurai
10 Replies

5. Shell Programming and Scripting

How to use SED to join multiple lines?

Hi guys, anyone know how can i join multiples lines using sed till the end of a file and output to another file in a single line? The end of each line will be replaced with a special char "#". I am using the below SED command, however it seems to remove the last 2 lines. Also not all lines... (12 Replies)
Discussion started by: DrivesMeCrazy
12 Replies

6. Shell Programming and Scripting

How to get awk to edit in place and join all lines in text file

Hi, I lack the utter fundamentals on how to craft an awk script. I have hundreds of text files that were mangled by .doc format so all the lines are broken up so I need to join all of the lines of text into a single line. Normally I use vim command "ggVGJ" to join all lines but with so many... (3 Replies)
Discussion started by: n00ti
3 Replies

7. UNIX for Dummies Questions & Answers

sed, join lines that do not match pattern

Hello, Could someone help me with sed. I have searched for solution 5 days allready :wall:, but cant find. Unfortunately my "sed" knowledge not good enough to manage it. I have the text: 123, foo1, bar1, short text1, dat1e, stable_pattern 124, foo2, bar2, long text with few lines, date,... (4 Replies)
Discussion started by: petrasl
4 Replies

8. Shell Programming and Scripting

Join the line on delimiter using sed/awk in UNIX

I've input as , abcd| ef 123456| 78| 90 Desired output as, abcdef 1234567890 Anyone please give the solution. (5 Replies)
Discussion started by: jinixvimal
5 Replies

9. Shell Programming and Scripting

awk join lines based on keyword

Hello , I will need your help once again. I have the following file: cat file02.txt PATTERN XXX.YYY.ZZZ. 500 ROW01 aaa. 300 XS 14 ROW 45 29 AS XD.FD. PATTERN 500 ZZYN002 ROW gdf gsste ALT 267 fhhfe.ddgdg. PATTERN ERE.MAY. 280 PATTERRNTH 5000 rt.rt. ROW SO a 678 PATTERN... (2 Replies)
Discussion started by: alex2005
2 Replies

10. UNIX for Beginners Questions & Answers

Sed/awk join lines once pattern found

Hi all OS - RHEL6.4 I have input file -f1.txt I need to search line which starts with \Start and read next line till it gets blank line and join them all. I need to trim any trailing spaces for each line.So output.txt should be.. \Start\now\fine stepwatch this space for toolsends... (7 Replies)
Discussion started by: krsnadasa
7 Replies
RRDGRAPH_EXAMPLES(1)						      rrdtool						      RRDGRAPH_EXAMPLES(1)

NAME
rrdgraph_examples - Examples for rrdtool graph SYNOPSIS
rrdtool graph /home/httpd/html/test.png --img-format PNG followed by any of the examples below DESCRIPTION
For your convenience some of the commands are explained here by using detailed examples. They are not always cut-and-paste ready because comments are intermixed with the examples. EXAMPLES
Data with multiple resolutions --end now --start end-120000s --width 400 DEF:ds0a=/home/rrdtool/data/router1.rrd:ds0:AVERAGE DEF:ds0b=/home/rrdtool/data/router1.rrd:ds0:AVERAGE:step=1800 DEF:ds0c=/home/rrdtool/data/router1.rrd:ds0:AVERAGE:step=7200 LINE1:ds0a#0000FF:"default resolutionl" LINE1:ds0b#00CCFF:"resolution 1800 seconds per intervall" LINE1:ds0c#FF00FF:"resolution 7200 seconds per intervall" Nicely formatted legend section DEF:ds0=/home/rrdtool/data/router1.rrd:ds0:AVERAGE DEF:ds1=/home/rrdtool/data/router1.rrd:ds1:AVERAGE VDEF:ds0max=ds0,MAXIMUM VDEF:ds0avg=ds0,AVERAGE VDEF:ds0min=ds0,MINIMUM VDEF:ds0pct=ds0,95,PERCENT VDEF:ds1max=ds1,MAXIMUM VDEF:ds1avg=ds1,AVERAGE VDEF:ds1min=ds1,MINIMUM VDEF:ds1pct=ds1,95,PERCENT Note: consolidation occurs here. CDEF:ds0bits=ds0,8,* CDEF:ds1bits=ds1,8,* Note: 10 spaces to move text to the right COMMENT:" " Note: the column titles have to be as wide as the columns COMMENT:"Maximum " COMMENT:"Average " COMMENT:"Minimum " COMMENT:"95th percentilel" AREA:ds0bits#00C000:"Inbound " GPRINT:ds0max:"%6.2lf %Sbps" GPRINT:ds0avg:"%6.2lf %Sbps" GPRINT:ds0min:"%6.2lf %Sbps" GPRINT:ds0pct:"%6.2lf %Sbpsl" LINE1:ds1bits#0000FF:"Outbound" GPRINT:ds1max:"%6.2lf %Sbps" GPRINT:ds1avg:"%6.2lf %Sbps" GPRINT:ds1min:"%6.2lf %Sbps" GPRINT:ds1pct:"%6.2lf %Sbpsl" Offsetting a line on the y-axis Depending on your needs you can do this in two ways: o Offset the data, then graph this DEF:mydata=my.rrd:ds:AVERAGE Note: this will also influence any other command that uses "data" CDEF:data=mydata,100,+ LINE1:data#FF0000:"Data with offset" o Graph the original data, with an offset DEF:mydata=my.rrd:ds:AVERAGE Note: no color in the first line so it is not visible LINE1:100 Note: the second line gets stacked on top of the first one LINE1:data#FF0000:"Data with offset":STACK Drawing dashed lines Also works for HRULE and VRULE o default style: - - - - - LINE1:data#FF0000:"dashed line":dashes o more fancy style with offset: - - --- - --- - LINE1:data#FF0000:"another dashed line":dashes=15,5,5,10:dash-offset=10 Time ranges Last four weeks: --start end-4w --end 00:00 January 2001: --start 20010101 --end start+31d January 2001: --start 20010101 --end 20010201 Last hour: --start end-1h Last 24 hours: <nothing at all> Yesterday: --end 00:00 Viewing the current and previous week together --end now --start end-1w DEF:thisweek=router.rrd:ds0:AVERAGE DEF:lastweek=router.rrd:ds0:AVERAGE:end=now-1w:start=end-1w Shift the data forward by one week (604800 seconds) SHIFT:lastweek:604800 [ more of the usual VDEF and CDEF stuff if you like ] AREA:lastweek#0000FF:Last week LINE1:thisweek#FF0000:This week Aberrant Behaviour Detection If the specialized function RRAs exist for aberrant behavior detection, they can be used to generate the graph of a time series with confidence bands and failures. rrdtool graph example.png DEF:obs=monitor.rrd:ifOutOctets:AVERAGE DEF:pred=monitor.rrd:ifOutOctets:HWPREDICT DEF:dev=monitor.rrd:ifOutOctets:DEVPREDICT DEF:fail=monitor.rrd:ifOutOctets:FAILURES TICK:fail#ffffa0:1.0:"Failures: Average bits out" CDEF:scaledobs=obs,8,* CDEF:upper=pred,dev,2,*,+ CDEF:lower=pred,dev,2,*,- CDEF:scaledupper=upper,8,* CDEF:scaledlower=lower,8,* LINE2:scaledobs#0000ff:"Average bits out" LINE1:scaledupper#ff0000:"Upper Confidence Bound: Average bits out" LINE1:scaledlower#ff0000:"Lower Confidence Bound: Average bits out" This example generates a graph of the data series in blue (LINE2 with the scaledobs virtual data source), confidence bounds in red (scaledupper and scaledlower virtual data sources), and potential failures (i.e. potential aberrant aberrant behavior) marked by vertical yellow lines (the fail data source). The raw data comes from an AVERAGE RRA, the finest resolution of the observed time series (one consolidated data point per primary data point). The predicted (or smoothed) values are stored in the HWPREDICT RRA. The predicted deviations (think standard deviation) values are stored in the DEVPREDICT RRA. Finally, the FAILURES RRA contains indicators, with 1 denoting a potential failure. All of the data is rescaled to bits (instead of Octets) by multiplying by 8. The confidence bounds are computed by an offset of 2 deviations both above and below the predicted values (the CDEFs upper and lower). Vertical lines indicated potential failures are graphed via the TICK graph element, which converts non-zero values in an RRA into tick marks. Here an axis-fraction argument of 1.0 means the tick marks span the entire y-axis, and hence become vertical lines on the graph. The choice of 2 deviations (a scaling factor) matches the default used internally by the FAILURES RRA. If the internal value is changed (see rrdtune), this graphing command should be changed to be consistent. A note on data reduction: The rrdtool graph command is designed to plot data at a specified temporal resolution, regardless of the actually resolution of the data in the RRD file. This can present a problem for the specialized consolidation functions which maintain a one-to-one mapping between primary data points and consolidated data points. If a graph insists on viewing the contents of these RRAs on a coarser temporal scale, the graph command tries to do something intelligent, but the confidence bands and failures no longer have the same meaning and may be misleading. SEE ALSO
rrdgraph gives an overview of how rrdtool graph works. rrdgraph_data describes DEF,CDEF and VDEF in detail. rrdgraph_rpn describes the RPN language used in the xDEF statements. rrdgraph_graph page describes all the graph and print functions. AUTHOR
Program by Tobias Oetiker <tobi@oetiker.ch> This manual page by Alex van den Bogaerdt <alex@vandenbogaerdt.nl> with corrections and/or additions by several people 1.4.7 2009-02-21 RRDGRAPH_EXAMPLES(1)
All times are GMT -4. The time now is 05:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy