Sponsored Content
Top Forums Shell Programming and Scripting add semicolumn and remove spaces Post 302424454 by Dedalus on Tuesday 25th of May 2010 09:06:54 AM
Old 05-25-2010
add semicolumn and remove spaces

Hi

I have a file like:
Code:
one  two         three  four          five
six   seven      eight  nine          ten

and I'd like to get
Code:
one:two:three:four:five

I'm trying to do it with sed, but the problem is also that the spaces between the words are not constant.
Any idea please?

thanks

D.

Last edited by Scott; 05-25-2010 at 10:11 AM.. Reason: Replaced QUOTE tags with CODE tags for better readability
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

adding semicolumn at end of line

Hi , I need to add semicolumn at the end of each line in a file. can any one help me in this? Thanks in advance (2 Replies)
Discussion started by: scorpio
2 Replies

2. Shell Programming and Scripting

Remove Spaces

Hi All, I have a comma seperated file. I wanna remove the spaces from column 2. I mean i don't wanna remove the spaces those are presnt in column 1. ex: emp name, emp no, salary abc k, abc 11, 1000 00 bhk s, bhk 22, 2000 00 the output should be: emp name, emp no, salary abc k, abc11,... (4 Replies)
Discussion started by: javeed7
4 Replies

3. Shell Programming and Scripting

remove spaces between tags

I am having the data.txt file as follows. ------- <RMService> <ResControl> <ResultCode>FATAL</ResultCode> <ServiceTime>38</ServiceTime> <DWLControl> <requesterLanguage>100</requesterLanguage> <requesterLocale>en</requesterLocale> <requesterName>NCO A Batch... (6 Replies)
Discussion started by: kmanivan82
6 Replies

4. UNIX for Dummies Questions & Answers

remove spaces in between file

hey, I have this file: ATOM 2510 HG12 VAL 160 8.462 15.861 1.637 ATOM 2511 HG13 VAL 160 9.152 14.510 0.725 ATOM 2512 CG2 VAL 160 6.506 16.579 -0.088 ATOM 2513 HG21 VAL 160 5.499 16.421 -0.478 ATOM 2514 HG22 VAL 160 6.417 16.984 ... (4 Replies)
Discussion started by: kanikasharma
4 Replies

5. Shell Programming and Scripting

remove spaces

Hi folks, I need to remove spaces at the end of each line in a *.txt file. it looks like this word 1 word 2 . . . word n i found some sed commands but any of them didnt work so far thank you for your posts (6 Replies)
Discussion started by: Jimmy7
6 Replies

6. Linux

How to remove spaces in the file?

hiii i have a file that contains spaces in the begining of a file till the middle the from there the txt would appear. hw can i remove those spaces and bring the text to the begining portion file1 text starts from here (12 Replies)
Discussion started by: anurupa777
12 Replies

7. Shell Programming and Scripting

Remove spaces in a file

Hi friends, I have a file1.txt 1 | a | 4757634 | jund jdkj | erhyj 2 | a | 4757634 | jnd jdkj | rhje hjrhwj i have used tr -d '\040' to remove the spcaes output file cat file1.txt | tr -d '\040' 1|a|4757634|jundjdkj|erhyj... (5 Replies)
Discussion started by: i150371485
5 Replies

8. Shell Programming and Scripting

How to remove spaces on a line?

Hi, suppose I have the following data: albert music=top40 age=20 bob music=punk rock age=25 candy music=r n b age=22 dave music=mozart or bach only age=30 I want to extract and manipulate the music column but it's got spaces in it. How can I substitute the space with an underscore... (2 Replies)
Discussion started by: almonds
2 Replies

9. Shell Programming and Scripting

Remove spaces from the file

Hi All, The output file contains data as below. "20141023","CUSTOMER" ,"COMPANY" ,"IN0515461" ,"" ,"JOSHUA" There are spaces in between the ending " and ,. The number of spaces is random. How can I remove that from the file so that the final output is:... (4 Replies)
Discussion started by: aarsh.dave
4 Replies

10. Shell Programming and Scripting

Trying to remove leading spaces

OS : RHEL 6.7 Shell : bash I am trying to remove the leading the spaces in the below file $ cat pattern2.txt hello1 hello2 hello3 hello4 Expected output is shown below. $ cat pattern2.txt hello1 hello2 hello3 hello4 (2 Replies)
Discussion started by: John K
2 Replies
Test::Fatal(3)						User Contributed Perl Documentation					    Test::Fatal(3)

NAME
Test::Fatal - incredibly simple helpers for testing code with exceptions VERSION
version 0.013 SYNOPSIS
use Test::More; use Test::Fatal; use System::Under::Test qw(might_die); is( exception { might_die; }, undef, "the code lived", ); like( exception { might_die; }, qr/turns out it died/, "the code died as expected", ); isa_ok( exception { might_die; }, 'Exception::Whatever', 'the thrown exception', ); DESCRIPTION
Test::Fatal is an alternative to the popular Test::Exception. It does much less, but should allow greater flexibility in testing exception-throwing code with about the same amount of typing. It exports one routine by default: "exception". FUNCTIONS
exception my $exception = exception { ... }; "exception" takes a bare block of code and returns the exception thrown by that block. If no exception was thrown, it returns undef. Achtung! If the block results in a false exception, such as 0 or the empty string, Test::Fatal itself will die. Since either of these cases indicates a serious problem with the system under testing, this behavior is considered a feature. If you must test for these conditions, you should use Try::Tiny's try/catch mechanism. (Try::Tiny is the underlying exception handling system of Test::Fatal.) Note that there is no TAP assert being performed. In other words, no "ok" or "not ok" line is emitted. It's up to you to use the rest of "exception" in an existing test like "ok", "isa_ok", "is", et cetera. Or you may wish to use the "dies_ok" and "lives_ok" wrappers, which do provide TAP output. "exception" does not alter the stack presented to the called block, meaning that if the exception returned has a stack trace, it will include some frames between the code calling "exception" and the thing throwing the exception. This is considered a feature because it avoids the occasionally twitchy "Sub::Uplevel" mechanism. Achtung! This is not a great idea: sub exception_like(&$;$) { my ($code, $pattern, $name) = @_; like( &exception($code), $pattern, $name ); } exception_like(sub { }, qr/foo/, 'foo appears in the exception'); If the code in the "..." is going to throw a stack trace with the arguments to each subroutine in its call stack (for example via "Carp::confess", the test name, "foo appears in the exception" will itself be matched by the regex. Instead, write this: like( exception { ... }, qr/foo/, 'foo appears in the exception' ); Achtung: One final bad idea: isnt( exception { ... }, undef, "my code died!"); It's true that this tests that your code died, but you should really test that it died for the right reason. For example, if you make an unrelated mistake in the block, like using the wrong dereference, your test will pass even though the code to be tested isn't really run at all. If you're expecting an inspectable exception with an identifier or class, test that. If you're expecting a string exception, consider using "like". success try { should_live; } catch { fail("boo, we died"); } success { pass("hooray, we lived"); }; "success", exported only by request, is a Try::Tiny helper with semantics identical to "finally", but the body of the block will only be run if the "try" block ran without error. Although almost any needed exception tests can be performed with "exception", success blocks may sometimes help organize complex testing. dies_ok lives_ok Exported only by request, these two functions run a given block of code, and provide TAP output indicating if it did, or did not throw an exception. These provide an easy upgrade path for replacing existing unit tests based on "Test::Exception". RJBS does not suggest using this except as a convenience while porting tests to use Test::Fatal's "exception" routine. use Test::More tests => 2; use Test::Fatal qw(dies_ok lives_ok); dies_ok { die "I failed" } 'code that fails'; lives_ok { return "I'm still alive" } 'code that does not fail'; AUTHOR
Ricardo Signes <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2013-09-23 Test::Fatal(3)
All times are GMT -4. The time now is 03:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy