Sponsored Content
Top Forums Shell Programming and Scripting Add a carriage return after every sorted field Post 302977122 by jacki on Tuesday 12th of July 2016 10:08:11 PM
Old 07-12-2016
Add a carriage return after every sorted field

Hi All,

I have a text file -

Code:
nmn-smt-1039.test.com:SearchService-WW:x:8277
nmn-smt-1102.test.com:AdminConsole-ww:x:8536
nmn-smt-1041.test.com:SearchService-WW:x:8277
nmn-wsf-1007.test.com:Service-ww:x:8532
nmn-smt-1042.test.com:SearchService-WW:x:8277
nmn-wsf-1008.test.com:Service-ww:x:8532

I am sorting it by field 2 using sort -t: -k2.

1)
I want to add a "carriage return" after every sorted field.So that the output become -

Code:
nmn-smt-1039.test.com:SearchService-WW:x:8277
nmn-smt-1041.test.com:SearchService-WW:x:8277
nmn-smt-1042.test.com:SearchService-WW:x:8277

nmn-smt-1102.test.com:AdminConsole-ww:x:8536

nmn-wsf-1007.test.com:Service-ww:x:8532
nmn-wsf-1008.test.com:Service-ww:x:8532

2)
Once 1 is done.
I want to introduce a text on places where there is a carriage return and place the last value in the field on it ($4).

So the file should become -

Code:
text:8277
nmn-smt-1039.test.com:SearchService-WW:x:8277
nmn-smt-1041.test.com:SearchService-WW:x:8277
nmn-smt-1042.test.com:SearchService-WW:x:8277
text:8536
nmn-smt-1102.test.com:AdminConsole-ww:x:8536
text:8532
nmn-wsf-1007.test.com:Service-ww:x:8532
nmn-wsf-1008.test.com:Service-ww:x:8532

thanks.
Moderator's Comments:
Mod Comment This is your fifth infraction for refusing to use CODE and ICODE tags in your posts.

Continued posting requiring moderators and administrators to edit your posts for you may result in being banned from this site.

Please use CODE tags when displaying sample input, sample output, and code segments as required by forum rules.

Last edited by Don Cragun; 07-13-2016 at 01:14 AM.. Reason: Add CODE and ICODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture carriage return.

I try to test the carriage return in a variable. $ LENGTH=`expr $VARIABLE : ".*"` will return the length of the variable. But this doesn't work if $VARIABLE has zero length. Any help will be well appreciated. Thanks in advance. Giovanni (4 Replies)
Discussion started by: gio123bg
4 Replies

2. Shell Programming and Scripting

Dont want carriage return

I have observed with print & echo, they produce carriage return <CR> or newline, after they display string next to them. Is there anyway to avoide these <CR> after the intended string is displayed? (3 Replies)
Discussion started by: videsh77
3 Replies

3. Shell Programming and Scripting

add carriage return at end of file

Hi I would like to add carriage return at end of file, because we need to mask the customer names for detailed records. Some what the file doesnot have carriage at end of line of last record.So that i 'll get 2 records when use ---aa.txt----- 1|aaa|bbb|ccc 2|bbbb|hghgh|ggg 000002 tail... (2 Replies)
Discussion started by: HAA
2 Replies

4. UNIX for Dummies Questions & Answers

carriage return and linefeed

hi can anyone please tell me the difference between carriage return, linefeed and newline ? (2 Replies)
Discussion started by: streetfi8er
2 Replies

5. Shell Programming and Scripting

2 carriage return within a record

Hi all, need your help in replacing carriage return in a record. Input: col1|col2|col3|col4|col5|col6|col7|col8|col9|col10 1|aa|bb|cc|dd|eee eee|ff|ggggg|hh hhh|iii 2|zz|yy|xx|ww|vv|uu|tt|ss|rr Output: col1|col2|col3|col4|col5|col6|col7|col8|col9|col10... (12 Replies)
Discussion started by: agathaeleanor
12 Replies

6. Shell Programming and Scripting

Carriage return ksh

Hello, How do i usecarriage return in ksh. I want to do an echo "bla bla" and another echo "bla bla" will appear and replace the first echo on screen. I tried: until ; do echo "bla bla \r" done please advice. Thanks. (3 Replies)
Discussion started by: LiorAmitai
3 Replies

7. Shell Programming and Scripting

Awk to remove carriage return from 65th field

Hi, I have a pipe delimited file. There are around 700 columns in the file. The 65th column has carriage return which is causing read issue with our ETL process. I would like to replace the new line characters in 65th field with "nothing" i have return the following code and need help to... (7 Replies)
Discussion started by: pinnacle
7 Replies

8. Shell Programming and Scripting

Substitute \n with carriage return

Hello all, I've a flat file in the following format: AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003 And I want to substitute \n with the carriage return. Any help is appreciated! Regards, - Seth (8 Replies)
Discussion started by: sethmj
8 Replies

9. UNIX for Dummies Questions & Answers

Remove carriage return

I need to remove the carriage return comes inbetween the record. Need to have CR only at the end. I used the below command. tr -d '\n' < filewithcarriagereturns > filewithoutcarriagereturns But its removing all the CR and giving one line output. Input File: 12345 abcdegh... (11 Replies)
Discussion started by: srvn_saru
11 Replies

10. UNIX for Beginners Questions & Answers

awk Command to add Carriage Return and Line Feed

Hello, Can someone please share a Simple AWK command to append Carriage Return & Line Feed to the end of the file, If the Carriage Return & Line Feed does not exist ! Thanks (16 Replies)
Discussion started by: rosebud123
16 Replies
Test::Harness::Results(3pm)				 Perl Programmers Reference Guide			       Test::Harness::Results(3pm)

NAME
Test::Harness::Results - object for tracking results from a single test file SYNOPSIS
One Test::Harness::Results object represents the results from one test file getting analyzed. CONSTRUCTION
new() my $results = new Test::Harness::Results; Create a test point object. Typically, however, you'll not create one yourself, but access a Results object returned to you by Test::Harness::Results. ACCESSORS
The following data points are defined: passing true if the whole test is considered a pass (or skipped), false if its a failure exit the exit code of the test run, if from a file wait the wait code of the test run, if from a file max total tests which should have been run seen total tests actually seen skip_all if the whole test was skipped, this will contain the reason. ok number of tests which passed (including todo and skips) todo number of todo tests seen bonus number of todo tests which unexpectedly passed skip number of tests skipped So a successful test should have max == seen == ok. There is one final item, the details. details an array ref reporting the result of each test looks like this: $results{details}[$test_num - 1] = { ok => is the test considered ok? actual_ok => did it literally say 'ok'? name => name of the test (if any) diagnostics => test diagnostics (if any) type => 'skip' or 'todo' (if any) reason => reason for the above (if any) }; Element 0 of the details is test #1. I tried it with element 1 being #1 and 0 being empty, this is less awkward. Each of the following fields has a getter and setter method. o wait o exit perl v5.10.0 2007-12-18 Test::Harness::Results(3pm)
All times are GMT -4. The time now is 03:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy