Sponsored Content
Top Forums Shell Programming and Scripting Remove new line starting with a numeric value and append it to the previous line Post 303020028 by nms on Thursday 12th of July 2018 08:47:10 AM
Old 07-12-2018
Remove new line starting with a numeric value and append it to the previous line

Hi,

i have a file with multiple entries. After some tests with sed i managed to get the file output as follows:

Code:
lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1,
00,2110597,2094790,0,81,529,75649011,56435363,
lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,
00,1019687575,1327955853,1,322,583,2810019516,1981897836,
lsn=TM1ITP1-AM1ITP2-LS,apc=501:0,state=avail,avail/links=1/1,
00,536022841,1334912507,0,277,966,2588691785,2512216939,
lsn=TM1ITP1-TMNLSTP1,apc=12309:1,state=avail,avail/links=4/4,
00,28422611,35850253,0,185,216,216892933,38975423,
01,66892965,50298069,0,250,8807,2591394100,803622868,
02,27488395,38094791,0,249,252,170335784,66760929,
03,27762094,19995809,0,251,258,216422353,2019547890,
lsn=TM1ITP1-TMNLSTP2,apc=12547:1,state=avail,avail/links=4/4,
00,80966204,16449140,0,47,121,1928336154,2818020786,
01,332655,171104,0,50,30,25432178,25498178,
02,55281799,11176343,0,93,145,4243472214,1907308254,
03,54060754,28585708,0,363,301,4174500371,4240529245,
lsn=X-LINK-IN1,apc=4882:1,state=avail,avail/links=1/1,
00,40085787,31652380,0,73,755,271023232,3802680330,

What i'm trying to perfrom now is to be able to shift any line starting with a number (in this case they all start with 0) to be shifted on to the next line. or maybe more simpler, all lines which do not begin with "lsn=" are to be appened to the previous line
Example:

Code:
lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1,00,2110597,2094790,0,81,529,75649011,56435363,
....
lsn=TM1ITP1-TMNLSTP2,apc=12547:1,state=avail,avail/links=4/4,00,80966204,16449140,0,47,121,1928336154,2818020786,01,332655,171104,0,50,30,25432178,25498178,02,55281799,11176343,0,93,145,4243472214,1907308254,03,54060754,28585708,0,363,301,4174500371,4240529245,

Is there a way with sed or tr?

---------- Post updated at 02:47 PM ---------- Previous update was at 02:30 PM ----------

ok it seems this does the trick!

Code:
awk 'BEGIN {accum_line = "";} /^lsn=/{if(length(accum_line)){print accum_line; accum_line = "";}} {accum_line = accum_line " " $0;} END {if(length(accum_line)){print accum_line; }}'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append line that does not contain pipe to it previous line

Hi All, I have a file which contains data as below When we see no pipe character in the line. append those lines to the previous line with pipe character till we get the next line with pipe character with ~(concat with ~) Input file looks like: 1080530944|001|john.l.bonner|Acknowledge|CN... (11 Replies)
Discussion started by: ainuddin
11 Replies

2. UNIX for Advanced & Expert Users

append the line with the previous if it not start with 1=

How to append the line with the previous if it not start with 1=. 1=ttt, 2=xxxxxx, 3=4545 44545, 4=66666, 1=ttt, 2=xxxxxx, 3=34434 3545, 4=66666, 5=ffffff 6=uuuuuuu, 7=ooooooo 1=ttt, 2=xxxxxx, 3=311343545, 4=66666 1=ttt, 2=xxxxxx, 5=XAXAXA, 7=FDFD (3 Replies)
Discussion started by: palsevlohit_123
3 Replies

3. Shell Programming and Scripting

SED or AWK "append line to the previous line"

Hi, How can I remove the line beak in the following case if the line begin with the special char “;”? TEXT Text;text ;text Text;text;text I want to convert the text to: Text;text;text Text;text;text I have already tried to use... (31 Replies)
Discussion started by: research3
31 Replies

4. Shell Programming and Scripting

Append each line to next previous line in a file

Hi all, Please help me in providing sample code to append the following 4 lines in one row. Input : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 RXOCF-430 HY1711 1 EXTERNAL ALARM DOOR ALARM Output should be : A1/EXT "BAPBSC10/07B/00" 523 090530 0115 ... (8 Replies)
Discussion started by: sudhakaryadav
8 Replies

5. Shell Programming and Scripting

Append specific lines to a previous line based on sequential search criteria

I'll try explain this as best I can. Let me know if it is not clear. I have large text files that contain data as such: 143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test line 2 test line 3 test 143593503 09-08-20 09:02:13... (3 Replies)
Discussion started by: jesse
3 Replies

6. Shell Programming and Scripting

Append next line to previous line when one pattern not found

Hi, I need help for below scenario.I have a flat file which is having records seperated by delimiters which will represent each record for oracle table.My Control file will consider each line as one record for that table. Some of the lines are aligned in two/three lines so that records are... (4 Replies)
Discussion started by: kannansr621
4 Replies

7. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

8. Shell Programming and Scripting

Append next line to previous lines when NF is less than 0

Hi All, This is very urgent, I've a data file with 1.7 millions rows in the file and the delimiter is cedilla and I need to format the data in such a way that if the NF in the next row is less than 1, it will append that value to previous line. Any help will be appricated. Thanks,... (17 Replies)
Discussion started by: cumeh1624
17 Replies

9. UNIX for Dummies Questions & Answers

How to remove fields space and append next line to previous line.?

awk 'BEGIN{FS = "Ç"} NR == 1 {p = $0; next} NF > 1 {print p; p = $0} NF <= 1 {p = (p " " $0)} END {print p}' input.txt > output.txt This is what the input data file looks like with broken lines Code: 29863 Ç890000000 Ç543209911 ÇCHNGOHG Ç000000001 Ç055 ... (4 Replies)
Discussion started by: cumeh1624
4 Replies

10. Shell Programming and Scripting

Issue while append to previous line

Hi, I have data as below. 36578019,005-923887317,UNMDL,20151230,2C3CCAAG4GH135448,L,TX,20160108,62,"030916 PPT TX AFF RPRT VALID AFF IN PDP WLL FWD TO RYAN ON 031116 CB1619 ",, 36580219,611-923785453,FC,20151209,ZACCJABT9FPC19274,L,TX,20160108,83,,,... (4 Replies)
Discussion started by: JSKOBS
4 Replies
Device::Cdio::Track(3pm)				User Contributed Perl Documentation				  Device::Cdio::Track(3pm)

NAME
Device::Cdio::Track - Class for track aspects of Device::Cdio. SYNOPSIS
use Device::Cdio::Device; use Device::Cdio::Track; $device = Device::Cdio::Device->new(-source=>'/dev/cdrom'); $track = $device->get_last_track(); print "track: %d, last lsn: %d ", $track->{track}, track->get_last_lsn(); $track = $device->get_first_track(); $format = $rackt->get_format(); METHODS
new new(device, track)->object Creates a new track object. get_audio_channels get_audio_channels(cdio, track)->int Return number of channels in track: 2 or 4. Not meaningful if track is not an audio track. -1 is returned on error and -2 if the driver doesn't support the operation. get_copy_permit get_copy_permit(cdio, track)->int Return copy protection status on a track. Is this meaningful not an audio track? get_format get_format()->$format Get the format (e.g. 'audio', 'mode2', 'mode1') of track. get_last_lsn get_last_lsn()->lsn Return the ending LSN for a track $perlcdio::INVALID_LSN is returned on error. get_lba get_lba()->lba Return the starting LBA for a track $perlcdio::INVALID_LBA is returned on error. get_lsn get_lsn()->lsn Return the starting LSN for a track $perlcdio::INVALID_LSN is returned on error. get_msf get_msf() Return the starting MSF (minutes/secs/frames) for track number track. Track numbers usually start at something greater than 0, usually 1. Returns string of the form mm:ss:ff if all good, or string 'error' on error. get_preemphasis get_preemphasis()->result Get linear preemphasis status on an audio track. This is not meaningful if not an audio track? get_track_sec_count item get_track_sec_count()->int Get the number of sectors between this track an the next. This includes any pregap sectors before the start of the next track. Track numbers usually start at something greater than 0, usually 1. $perlcdio::INVALID_LSN is returned on error. is_track_green is_track_green(cdio, track) -> bool Return True if we have XA data (green, mode2 form1) or XA data (green, mode2 form2). That is track begins: sync - header - subheader 12 4 - 8 get_track_isrc $isrc = $track->get_track_isrc; Returns an empty string or the International Standard Recording Code. Which is presented in 4 hyphen separated substrings: "CC-XXX-YY- NNNNN" "CC" two-character ISO 3166-1 alpha-2 country code "XXX" is a three character alphanumeric registrant code "YY" is the last two digits of the year of registration (NB not necessarily the date the recording was made) "NNNNN" is a unique 5-digit number identifying the particular sound recording. set_track set_track(track_num) Set a new track number. SEE ALSO
Device::Cdio is the top-level module, Device::Cdio::Device is a class device objects, and Device::Cdio::ISO9660 for working with ISO9660 systems. perlcdio is the lower-level interface to libcdio. <http://www.gnu.org/software/libcdio/doxygen/track_8h.html> is documentation via doxygen of "libiso9660". AUTHORS
Rocky Bernstein "<rocky at cpan.org>". COPYRIGHT
Copyright (C) 2006 Rocky Bernstein <rocky@cpan.org> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. perl v5.14.2 2012-06-22 Device::Cdio::Track(3pm)
All times are GMT -4. The time now is 05:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy