Sponsored Content
Top Forums Shell Programming and Scripting Sed wraps some lines, not all Post 302505622 by alan on Thursday 17th of March 2011 12:43:15 PM
Old 03-17-2011
Quote:
Originally Posted by LivinFree
Here's my crack at it, although if you're working with huge files, it might not be a great idea to load that much into the Hold buffer:
Code:
sed -n '1h;2,$H;${g;s/\n/\t/g;s/\tReceiver/\nReceiver/g;p}' infile

Or in shell:
Code:
#! /bin/bash
while read line; do
    [[ "$line" =~ PowerOnHours ]] && { 
        printf '%s\n' "$line"
    } || {
        printf '%s\t' "$line"
    }
done <infile

Both suggestions worked great! I don't even have to add a newline after the PowerOnHours field (no added value, really). Your solution with bash is very straightforward, perfect for my big files.

---------- Post updated at 09:43 AM ---------- Previous update was at 09:41 AM ----------

Quote:
Originally Posted by fpmurphy
Elegant solution, Rdcwayx!

Some versions of sed do not support the \t syntax.

This should work on all platforms:
Code:
xargs -n4 < file | tr " " "\t"

I respectfully disagree. This suggestion gives me the following output

Code:
Receiver    ID    =    028908221899
Serial    Number    =    WD-WCASU6774998
Current    temp    =    37C
PowerOnHours    =    17434h

Not what I am looking for.

LivinFree got it right though. Check out his solution.Smilie This is what I was looking for:

Code:
Receiver ID   = 028935846791    Serial Number = WD-WCAV90944398 Current temp  = 51C     PowerOnHours  = 8896h
Receiver ID   = 028938701381    Serial Number = WD-WCAV91967340 Current temp  = 47C     PowerOnHours  = 6856h
Receiver ID   = 028938656577    Serial Number = WD-WCAV91257990 Current temp  = 48C     PowerOnHours  = 7670h

Thanks guys, you're all aces!!
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Pinting a file on Solaris 8 that wraps around.

Can someone please explain how I can print a file and get the text to wrap around instead of truncating the line and missing the rest of the text? There are a few reports that were generated and I am trying to print them but after wasting 200 sheets of paper I realized that the lines were... (1 Reply)
Discussion started by: rtoba
1 Replies

2. UNIX for Dummies Questions & Answers

how to use sed to get last 6 lines

dear experts, Sorry im a newbie. i have a file called INA.txt and it contains How do i get the 6 lines before "INA 2007-09-05" to appear? I tried using grep -A6, it doesnt work. Pls help. (5 Replies)
Discussion started by: aismann
5 Replies

3. Shell Programming and Scripting

sed problem - delete all lines until a match on 2 lines

First of all, I know this can be more eassily done with perl or other scripting languages but, that's not the issue. I need this in sed. (or wander if it's possible ) I got a file (trace file to recreate the control file from oracle for the dba boys) which contains some lines another line... (11 Replies)
Discussion started by: plelie2
11 Replies

4. Shell Programming and Scripting

bash script too many fields wraps to multiple lines

Hello. I'm trying to write a script to take a 5 field file, do some math, and extend it to 9 fields. Problem is, the script keeps wrapping it to two lines, even tho 9 fields, tab separated (even comma separated) doesn't fill the screen. Even if it did, I'm eventually copying it to an excel ... (2 Replies)
Discussion started by: JoeNess
2 Replies

5. Shell Programming and Scripting

sed show lines text between 2 blank lines

I have a file like blah blah blah blah this is the text I need, which might be between 1-4 lines, but always has a blank line above and below it, and is at the end of the text file the code tags don't show the trailing blank line. I started by deleting the last blank line with: ... (2 Replies)
Discussion started by: unclecameron
2 Replies

6. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

7. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

8. Shell Programming and Scripting

sed print all lines between second and third identical lines

I am trying to extract a table of data (mysql query output) from a log file. I need to print everything below the header and not past the end of the table. I have spent many hours searching with little progress. I am matching the regexp +-\{99\} with no problem. I just can't figure out how to print... (5 Replies)
Discussion started by: godfreydanials
5 Replies

9. Shell Programming and Scripting

Use sed to print first n lines and last n lines of an output.

Use sed to print first n lines and last n lines of an output. For example: n=10 Can it be done? Thanks. (7 Replies)
Discussion started by: carloszhang
7 Replies

10. Shell Programming and Scripting

ksh sed - Extract specific lines with mulitple occurance of interesting lines

Data file example I look for primary and * to isolate the interesting slot number. slot=`sed '/^primary$/,/\*/!d' filename | tail -1 | sed s'/*//' | awk '{print $1" "$2}'` Now I want to get the Touch line for only the associate slot number, in this case, because the asterisk... (2 Replies)
Discussion started by: popeye
2 Replies
All times are GMT -4. The time now is 08:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy