Sponsored Content
Top Forums Shell Programming and Scripting Join in a single line variable number of lines Post 302340145 by cfajohnson on Sunday 2nd of August 2009 11:59:19 PM
Old 08-03-2009

Code:
awk '/^761/ {
   if ( NR > 1 ) print line
   line = $0
   next
 }
 { line = line " " $0 }
' "$file"

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending line number to each line and getting total number of lines

Hello, I need help in appending the line number of each line to the file and also to get the total number of lines. Can somebody please help me. I have a file say: abc def ccc ddd ffff The output should be: Instance1=abc Instance2=def Instance3=ccc Instance4=ddd Instance5=ffff ... (2 Replies)
Discussion started by: chiru_h
2 Replies

2. Shell Programming and Scripting

Edit number of lines in a file to single line

Greetings, I have a file: hostnames.txt which has - # cat hostnames.txt machine1 machine2 I need the output to be saved to a variable as: HOSTNAMELIST=machine1,machine2 Please advise. Thanks, Chiru (3 Replies)
Discussion started by: chiru_h
3 Replies

3. Shell Programming and Scripting

join lines on line break in files

i had a file where lines appear to be broken when they shouldn't eg Line 1. kerl abc sdskd sdsjkdlsd sdsdksd \ Line 2. ksdkks sdnjs djsdjsd i can do a shift join to combine the lines but i there are plenty of files with this issue Line 1. kerl abc sdskd sdsjkdlsd sdsdksd ksdkks sdnjs... (6 Replies)
Discussion started by: mad_man12
6 Replies

4. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

5. Shell Programming and Scripting

How to use Perl to join multi-line into single line

Hello, Did anyone know how to write a perl script to merge the multi-line into a single line where each line with start at timestamp Input--> timestamp=2009-11-10-04.55.20.829347; a; b; c; timestamp=2009-11-10-04.55.20.829347; aa; bb; cc; (5 Replies)
Discussion started by: happyday
5 Replies

6. Shell Programming and Scripting

join based on line number when one file is missing lines

I have a file that contains 87 lines, each with a set of coordinates (x & y). This file looks like: 1 200.3 -0.3 2 201.7 -0.32 ... 87 200.2 -0.314 I have another file which contains data that was taken at certain of these 87 positions. i.e.: 37 125 42 175 86 142 where the first... (1 Reply)
Discussion started by: jackiev
1 Replies

7. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

8. Shell Programming and Scripting

[Perl] Split lines into array - variable line items - variable no of lines.

Hi, I have the following lines that I would like to see in an array for easy comparisons and printing: Example 1: field1,field2,field3,field4,field5 value1,value2,value3,value4,value5Example 2: field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies

9. Shell Programming and Scripting

Join two lines into one, but the second line only the last two columns

Hi guys, I hope you are doing well! I have a file and I need to join two lines into one, but the second line I need only the last two columns. ================= "eHealth Trend Report","logoRpt" "LAN/WAN Group 123" "Divide by Time" "switch1_a-RH-Serial0" "BW: 1.02 M" ... (4 Replies)
Discussion started by: antoniorajr
4 Replies

10. Shell Programming and Scripting

Help to join separate lines in a single one from xml file

Hi all, I need help to parse this xml file that has paragraphs broken in different lines and I would like to join in a single line. I hope you can understand my explanation. Thanks for any help/direction. The script could be in bash, awk, ruby, perl whatever please In the output I want:... (8 Replies)
Discussion started by: Ophiuchus
8 Replies
BIND::Config::Parser(3pm)				User Contributed Perl Documentation				 BIND::Config::Parser(3pm)

NAME
BIND::Config::Parser - Parse BIND Config file. SYNOPSIS
use BIND::Config::Parser; # Create the parser my $parser = new BIND::Config::Parser; my $indent = 0; # Set up callback handlers $parser->set_open_block_handler( sub { print " " x $indent, join( " ", @_ ), " { "; $indent++; } ); $parser->set_close_block_handler( sub { $indent--; print " " x $indent, "}; "; } ); $parser->set_statement_handler( sub { print " " x $indent, join( " ", @_ ), "; "; } ); # Parse the file $parser->parse_file( "named.conf" ); DESCRIPTION
BIND::Config::Parser provides a lightweight parser to the configuration file syntax of BIND v8 and v9 using a "Parse::RecDescent" grammar. It is in a similar vein to "BIND::Conf_Parser". However, as it has no knowledge of the directives, it doesn't need to be kept updated as new directives are added, it simply knows how to carve up a BIND configuration file into logical chunks. CONSTRUCTOR
new( ); Create a new "BIND::Config::Parser" object. METHODS
set_open_block_handler( CODE_REF ); Set the code to be called when a configuration block is opened. At least one argument will be passed; the name of that block, for example "options" or "zone", etc. as well as any additional items up to but not including the opening curly brace. set_close_block_handler( CODE_REF ); Set the code to be called when a configuration block is closed. No arguments are passed. set_statement_handler( CODE_REF ); Set the code to be called on a single line configuration element. At least one argument will be passed; the name of that element, as well as any additional items up to but not including the ending semi-colon. parse_file( FILENAME ); Parse FILENAME, triggering the above defined handlers on the relevant sections. TODO
Probably the odd one or two things. I'm fairly sure the grammar is correct. COPYRIGHT AND LICENSE
Copyright (c) 2005 Matt Dainty. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHORS
Matt Dainty <matt@bodgit-n-scarper.com>. SEE ALSO
perl, Parse::RecDescent, BIND::Conf_Parser. perl v5.14.2 2005-06-26 BIND::Config::Parser(3pm)
All times are GMT -4. The time now is 01:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy