Sponsored Content
Top Forums Shell Programming and Scripting Add a carriage return after every sorted field Post 302977126 by Don Cragun on Wednesday 13th of July 2016 12:59:05 AM
Old 07-13-2016
The output you provided for your sample input doesn't even come close to your stated requirements.

You said you want to sort on fields 2, 3, 4, and 1 which with your sample input would be:
Code:
nmn-smt-1102.test.com:AdminConsole-ww:x:8536
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-wsf-1007.test.com:Service-ww:x:8532
nmn-wsf-1008.test.com:Service-ww:x:8532

Then you say you want to insert a carriage return after every sorted field which would insert four <carriage-return> characters into each line of your output (shown below using <CR> as a representation of the <carriage-return> characters instead of using actual <carriage-return> characters which would cause overprinting of characters in your output lines:
Code:
nmn-smt-1102.test.com<CR>:AdminConsole-ww<CR>:x<CR>:8536<CR>
nmn-smt-1039.test.com<CR>:SearchService-WW<CR>:x<CR>:8277<CR>
nmn-smt-1041.test.com<CR>:SearchService-WW<CR>:x<CR>:8277<CR>
nmn-smt-1042.test.com<CR>:SearchService-WW<CR>:x<CR>:8277<CR>
nmn-wsf-1007.test.com<CR>:Service-ww<CR>:x<CR>:8532<CR>
nmn-wsf-1008.test.com<CR>:Service-ww<CR>:x<CR>:8532<CR>

If what you meant was that you wanted to insert an empty LINE after every change in the field 4 value in the sorted output and add the string txt. followed by the field 4 value on the preceding lines in that group, that output would be:
Code:
nmn-smt-1102.test.com:AdminConsole-ww:x:8536
txt:8536
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
txt:8277
nmn-wsf-1007.test.com:Service-ww:x:8532
nmn-wsf-1008.test.com:Service-ww:x:8532
txt:8532

But, of course, your sample output has SearchService-WW sorting before AdminConsole-ww and puts the inserted lines before changes in field 4 values instead of after.

Please explain these discrepancies and provide new sample output (in CODE tags), new requirements, or both so that the output you show us matches the requirements you have provided.
 

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
CBTEST(1)						      Quick Database Manager							 CBTEST(1)

NAME
cbtest - test cases for QDBM Cabin SYNOPSIS
cbtest sort [-d] rnum cbtest strstr [-d] rnum cbtest list [-d] rnum cbtest map [-d] rnum cbtest wicked rnum cbtest misc DESCRIPTION
The command `cbtest' is a utility for facility test and performance test. Measure the execution time of the command. This command is used in the following format. `rnum' specifies the number of records. cbtest sort [-d] rnum Perform test of sorting algorithms. cbtest sort [-d] rnum Perform test of string locating algorithms. cbtest list [-d] rnum Perform writing test of list. cbtest map [-d] rnum Perform writing test of map. cbtest wicked rnum Perform updating operations of list and map selected at random. cbtest misc Perform test of miscellaneous routines. Options feature the following. -d : read and show data of the result. This command returns 0 on success, another on failure. SEE ALSO
qdbm(3), cabin(3) AUTHOR
QDBM was written by Mikio Hirabayashi <mikio@fallabs.com>. Man Page 2005-06-01 CBTEST(1)
All times are GMT -4. The time now is 11:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy