Appending CRLF to end of record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending CRLF to end of record
# 1  
Old 12-19-2014
Appending CRLF to end of record

I need to append |\r\n (a pipe character and CRLF) at end of each record in Unix to all records where they are not already present.

So first check for the presence of |\r\n and if absent append it else do nothing
# 2  
Old 12-19-2014
Hello Abhilash,

Could you please provide some test input for same.

Thanks,
R. Singh
# 3  
Old 12-19-2014
Code:
awk '{$0=$0 ~ /\|\r\n$/?$0:$0"|\r\n"} 1' filename>output

worked for me
# 4  
Old 12-19-2014
This request, or highly similar ones, have been covered in these fora umpteen times. Did you consider a search upfront?

Depending on your system version, this may do:
Code:
sed '/|\r$/!s/$/|\r/' file

Please be aware that it looks for the combination you specified; should there be e.g. a single "|" at line end, a "|"\r combination will be added.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Appending | (pipe) to end of each line which does not have it

I have a text file in which all records end with pipe character and newline, but a few do not have a pipe at the end. Something like this 1|John|32|US| 2|Matt|35|UK 3|Rex|36|EU| So in the above example the second line does not have a pipe at the end My requirement is to append a... (5 Replies)
Discussion started by: abhilashnair
5 Replies

2. Shell Programming and Scripting

Appending ErrorCodes to the corresponding error record

Hi, Here i'm using a awk inside bash script to validate the datafile by referring to the configuration file(schema file). Here the validation check is done for datatype, field length and null values. Once the validation is done on data file the error records are moved to the bad file. So... (22 Replies)
Discussion started by: shree11
22 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Appending beginning of filename to end

Hi Guys, I have serveral directories like this: (2013) blablabla(blabla) - blabla (blabla) or (1997) blablabla(blabla) - blabla (blabla) and have to rename them to something like that: blablabla(blabla) - blabla (blabla) (2013) and blablabla(blabla) - blabla (blabla) (1997) Easy... (2 Replies)
Discussion started by: Nateshift
2 Replies

4. UNIX for Dummies Questions & Answers

Confusion with CRLF (wint) and LF (unix) as end of line seperators

I know that windows uses CRLF as a end of line character while Unix uses LF. But visually i could not see any difference in files while creating on either of plat forms. CR (Carriage Return) means to bring cursor to beginning of line while LF (Line feed) means to bring cursor to next line... (5 Replies)
Discussion started by: sarbjit
5 Replies

5. Shell Programming and Scripting

Appending a new field at the end in a file

can anyone tell me please ......how to append a new field at the end of a file with the help of sed or some other command in bourne shell (8 Replies)
Discussion started by: amitpta
8 Replies

6. UNIX for Dummies Questions & Answers

Sed $ appending to front, not to the end

I keep trying to append some astrix to the end of a line, but it keeps overwriting at the front of the line. These are the originals Fred Fardbarkle:674-843-1385:20 Parak Lane, Duluth, MN 23850:4/12/23:780900 Fred Fardbarkle:674-843-1385:20 Parak Lane, Duluth, MN 23850:4/12/23:780900 ... (5 Replies)
Discussion started by: DrSammyD
5 Replies

7. Shell Programming and Scripting

Appending data to the end of a line

I have searched the forms and I can not find info on appending each line of one file to the same line of another file. I know that I can cat one file to another or append the 2nd file to the end of the 1st but not quite sure how to append one line of data to another. For example File 1 has ... (2 Replies)
Discussion started by: scw132
2 Replies

8. Shell Programming and Scripting

Appending string at the end of the file

Hello, I wanted to append 'XYZ' at the end of the text file. How can i do this? I searched the forums and i am not getting what i want. Any help is highly appreciated. Thanks (2 Replies)
Discussion started by: govindts
2 Replies

9. Shell Programming and Scripting

appending date at the end of the file

I have file called xx Now i want to rename this file as xxYYYYMMDD_HHMIAM.xls Here is my code.. export DATE1=`date +%Y%m%d` mv xx xx$DATE1 This code renames as xxYYYYMMDD Now how can i append HHMIAM at the end of the file? Any help is appreciated... (3 Replies)
Discussion started by: govindts
3 Replies

10. Shell Programming and Scripting

appending spaces to first line based on second record.

Hi, I have a situation to append spaces to end of first record (header)and last record (footer) based on second record length. The first record length is always 20.The second record will be different for different files.I have to append spaces for the first line based on second record... (2 Replies)
Discussion started by: ammu
2 Replies
Login or Register to Ask a Question