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
GO-TESTFLAG(7)						 Miscellaneous Information Manual					    GO-TESTFLAG(7)

NAME
go - tool for managing Go source code DESCRIPTION
The 'go test' command takes both flags that apply to 'go test' itself and flags that apply to the resulting test binary. The test binary, called pkg.test, where pkg is the name of the directory containing the package sources, has its own flags: -test.v Verbose output: log all tests as they are run. -test.run pattern Run only those tests and examples matching the regular expression. -test.bench pattern Run benchmarks matching the regular expression. By default, no benchmarks run. -test.cpuprofile cpu.out Write a CPU profile to the specified file before exiting. -test.memprofile mem.out Write a memory profile to the specified file when all tests are complete. -test.memprofilerate n Enable more precise (and expensive) memory profiles by setting runtime.MemProfileRate. See 'godoc runtime MemProfileRate'. To pro- file all memory allocations, use -test.memprofilerate=1 and set the environment variable GOGC=off to disable the garbage collector, provided the test can run in the available memory without garbage collection. -test.parallel n Allow parallel execution of test functions that call t.Parallel. The value of this flag is the maximum number of tests to run simultaneously; by default, it is set to the value of GOMAXPROCS. -test.short Tell long-running tests to shorten their run time. It is off by default but set during all.bash so that installing the Go tree can run a sanity check but not spend time running exhaustive tests. -test.timeout t If a test runs longer than t, panic. -test.benchtime n Run enough iterations of each benchmark to take n seconds. The default is 1 second. -test.cpu 1,2,4 Specify a list of GOMAXPROCS values for which the tests or benchmarks should be executed. The default is the current value of GOMAXPROCS. For convenience, each of these -test.X flags of the test binary is also available as the flag -X in 'go test' itself. Flags not listed here are passed through unaltered. For instance, the command go test -x -v -cpuprofile=prof.out -dir=testdata -update will compile the test binary and then run it as pkg.test -test.v -test.cpuprofile=prof.out -dir=testdata -update AUTHOR
This manual page was written by Michael Stapelberg <stapelberg@debian.org>, for the Debian project (and may be used by others). 2012-05-13 GO-TESTFLAG(7)
All times are GMT -4. The time now is 04:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy