Sponsored Content
Operating Systems HP-UX How to remove new line character and append new line character in a file? Post 302466488 by ctsgnb on Tuesday 26th of October 2010 01:20:52 PM
Old 10-26-2010
Code:
sed 's: *\\n *: :g;s: *, *:,:g' infile

This would also remove space touching coma.

or
Code:
sed 's:\\n: :g;s:  *: :g' infile

s substitute
: separator
\\n pattern to replace (the \ is used to desactivate the \n )
<space> new pattern
g subtitution takes place globaly in the line even if more than 1 occurrence occur

the second substitution crush any number of space character into one in the line so you will never have more than 1 single space


Code:
# cat in
ID,Client ,SNo,Rank
37,Airtel \n Private \n limited,100,999\n
38,Vodaphone India \n Private Limited,200,888\n
39,Dell Limited,300,777\n
40,HP India Ltd\n,400,666\n
# sed 's:\\n: :g;s:  *: :g' in
ID,Client ,SNo,Rank
37,Airtel Private limited,100,999
38,Vodaphone India Private Limited,200,888
39,Dell Limited,300,777
40,HP India Ltd ,400,666
#

... could be gather in one substitution

Code:
sed 's: *\\n *: :g' in

a \n preceeded or followed by any number of space (even 0) is replaced by one single space

Last edited by ctsgnb; 10-26-2010 at 02:35 PM..
These 2 Users Gave Thanks to ctsgnb For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using SED to append character to each line

Hey - my first post here, and I'm a total SED newb. I've looked around for previous help on this, but have so far been unsuccessful. I have a program (AMStracker for OS X) that outputs data in the terminal. Output is in this form: . . . 3 0 -75 3 0 -76 3 0 -77 ... (4 Replies)
Discussion started by: c0nn0r
4 Replies

2. Shell Programming and Scripting

append a character at end of each line of a file

Hi, i want to append a character '|' at end of each line of a file abc.txt. for example if the file abc.txt conatins: a|b|c 1|2|33 w|2|11 i want result file xyz.txt a|b|c| 1|2|33| w|2|11| I know this is simple but sumhow i am not able to reach end of line. its urgent, thanks for... (4 Replies)
Discussion started by: muaz
4 Replies

3. Shell Programming and Scripting

How to append a character to the last but one field on a specific line?

Hi Guys, I have a file like this: aaa b c d e f fsss g h i k l qqq r t h n I want: aaa b c d e f fsss g h i k l qqq r t h , n ggg p t e d u qqq i o s , k (2 Replies)
Discussion started by: npatwardhan
2 Replies

4. Shell Programming and Scripting

How to remove line break character in a file

Hi, we are trying to process a csv file,in which we are getting data with line breaks.How to remove the line break character in the file? when i try to print the line break charcter using od -c,it gives as '\n' character for both line break and line feed. Please provide your valuable... (6 Replies)
Discussion started by: cnraja
6 Replies

5. Shell Programming and Scripting

How to remove new line character at end of file.

I need to remove new line character from end of file. Suppose here are content. a|b|c|d|r a|b|c|d|r a|b|c|d|r <new line> that means file contains 4 lines but data is there in 3 lines. so I want that only 3 lines should be there in file. Please help (20 Replies)
Discussion started by: varun940
20 Replies

6. Shell Programming and Scripting

Remove the last character (,) for every line in a file

Good afternoon: im working wih 2 files to find differences and use the cmp command cmp file1 file2 file1 file2 are are diifferent char 302 line1 i found what the difference is with the sed command and that is the file1 at the end of every line has a (,) (comma) character. i.e sed -n... (4 Replies)
Discussion started by: alexcol
4 Replies

7. Shell Programming and Scripting

Remove new line character and add space to convert into fixed width file

I have a file with different record length. The file as to be converted into fixed length by appending spaces at the end of record. The length should be calculated based on the record with maximum length in the file. If the length is less than the max length, the spaces should be appended... (4 Replies)
Discussion started by: Amrutha24
4 Replies

8. Shell Programming and Scripting

How to Remove comma as last character in end of last line of file?

how to Remove comma as last charector in end of last line of file: example: input file --------------- aaaaaa, bbbbbb, cccc, 12345, ____________ output file : ----------- aaaaaa, bbbbbb, (6 Replies)
Discussion started by: RahulJoshi
6 Replies

9. UNIX for Dummies Questions & Answers

How to remove $ or new line character in a file?

Hi All, Could any one suggest how to remove $ symbol in a text file when i am opening in vi editor. Scenario; For example iam having a file name aaa.txt the data inside the file is like sample name when i am opening in vi editor The same file resembles like below when i am... (1 Reply)
Discussion started by: Chandru_Raj
1 Replies

10. UNIX for Beginners Questions & Answers

Append each line based upon the character size

I have a huge file which contains multiple lines. It need to check whether character length is not more than 255 each line. If its not then it should remove the character up to column. I have described in the output below. If its more than that the next line should start with call but if the... (1 Reply)
Discussion started by: JoshvaPeter
1 Replies
PASTE(1)						    BSD General Commands Manual 						  PASTE(1)

NAME
paste -- merge corresponding or subsequent lines of files SYNOPSIS
paste [-s] [-d list] file ... DESCRIPTION
The paste utility concatenates the corresponding lines of the given input files, replacing all but the last file's newline characters with a single tab character, and writes the resulting lines to standard output. If end-of-file is reached on an input file while other input files still contain data, the file is treated as if it were an endless source of empty lines. The options are as follows: -d list Use one or more of the provided characters to replace the newline characters instead of the default tab. The characters in list are used circularly, i.e., when list is exhausted the first character from list is reused. This continues until a line from the last input file (in default operation) or the last line in each file (using the -s option) is displayed, at which time paste begins selecting characters from the beginning of list again. The following special characters can also be used in list: newline character tab character \ backslash character Empty string (not a null character). Any other character preceded by a backslash is equivalent to the character itself. -s Concatenate all of the lines of each separate input file in command line order. The newline character of every line except the last line in each input file is replaced with the tab character, unless otherwise specified by the -d option. If '-' is specified for one or more of the input files, the standard input is used; standard input is read one line at a time, circularly, for each instance of '-'. The paste utility exits 0 on success, and >0 if an error occurs. SEE ALSO
cut(1) STANDARDS
The paste utility is expected to be IEEE Std 1003.2 (``POSIX.2'') compatible. BSD
June 6, 1993 BSD
All times are GMT -4. The time now is 07:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy