Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Appending | (pipe) to end of each line which does not have it Post 302928467 by RavinderSingh13 on Friday 12th of December 2014 01:58:48 AM
Old 12-12-2014
Quote:
Originally Posted by abhilashnair
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 pipe to all such lines where it is missing
i tried
sed '/|/s/.*/&|/' filename
But this one appends a pipe to all lines irrespective of the fact that it is already present or not
Please suggest
Hello abhilashnair,

Kindly use code tags for commands and codes which you are using in your posts as per forum rules.
Following may help you in same.
Code:
awk '{$0=$0 ~ /\|$/?$0:$0"|"} 1'  Input_file

Output will be as follows.
Code:
1|John|32|US|
2|Matt|35|UK|
3|Rex|36|EU|

Here is the link for forum rules which may help you in understanding the rules of forum too.
https://www.unix.com/misc.php?do=cfrules

Thanks,
R. Singh

Last edited by RavinderSingh13; 12-12-2014 at 03:00 AM.. Reason: Added forum rules link now
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

appending a line to the end of several hundred files

I have a bunch of files named publish.php within subdirs. I need to append a line at the end of each file. I thought I could do it with find and echo like this: find . -name publish.php -exec echo "<? include('path/to/file.php'); ?>" >> '{}' \; but that appends the line to a file named {}... (2 Replies)
Discussion started by: surroscape
2 Replies

2. 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

3. 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

4. Shell Programming and Scripting

Filename pattern match and appending pipe

Hi, I have a directory with around 100k files and files with varying sizes(10GB files to as low as 5KB). All the files are having pipe dilimited records. I need to append 7 pipes to the end of each record, in each file whose name contains _X3_ and need to append 10 pipes to the end of each... (3 Replies)
Discussion started by: nss280
3 Replies

5. Shell Programming and Scripting

Appending the first word of each line to the end of each line

Hi Experts, Am relatively new to shell programming so would appreciate some help in this regard. I am looking at reading from a file, line by line, picking the first word of each line and appending it to the end of the line. Any suggestions? INPUT FILE - 3735051 :... (7 Replies)
Discussion started by: hj007
7 Replies

6. 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

7. 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

8. Shell Programming and Scripting

appending a blank line for a group of files at the end

hi, i m having a group of files starting with name 'Itemdelete<timestamp>' . my requirment is to append a blank line at the end of files ,using unix in all the Itemdelete* files with a single unix command without using scripts.can any body put some light to this requiremnt. regards Angel (4 Replies)
Discussion started by: angel12345
4 Replies

9. UNIX for Dummies Questions & Answers

Appending Date at the end ONLY in first line of file

Hi, My requirement is to append a date in format DDMMYYYYHHMISS at the end of first line of file which is HEADER. I am trying command sed -i '1s/.*/&<date_format>/' <file_name> Where <date_format>=`date +%m%d%Y%H%M%S` I am somehow misisng the right quotes ti get this added in above... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

10. Shell Programming and Scripting

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 (3 Replies)
Discussion started by: abhilashnair
3 Replies
connld(7M)							  STREAMS Modules							connld(7M)

NAME
connld - line discipline for unique stream connections SYNOPSIS
#include </sys/steam.h> int ioctl(fd,I_PUSH,"connld"); DESCRIPTION
connld is a STREAMS-based module that provides unique connections between server and client processes. It can only be pushed (see streamio(7I)) onto one end of a STREAMS-based pipe that may subsequently be attached to a name in the file system name space with fattach(3C). After the pipe end is attached, a new pipe is created internally when an originating process attempts to open(2) or creat(2) the file system name. A file descriptor for one end of the new pipe is packaged into a message identical to that for the ioctl I_SENDFD (see streamio(7I)) and is transmitted along the stream to the server process on the other end. The originating process is blocked until the server responds. The server responds to the I_SENDFD request by accepting the file descriptor through the I_RECVFD ioctl message. When this happens, the file descriptor associated with the other end of the new pipe is transmitted to the originating process as the file descriptor returned from open(2) or creat(2). If the server does not respond to the I_SENDFD request, the stream that the connld module is pushed on becomes uni-directional because the server will not be able to retrieve any data off the stream until the I_RECVFD request is issued. If the server process exits before issuing the I_RECVFD request, the open(2) or the creat(2) invocation will fail and return -1 to the originating process. When the connld module is pushed onto a pipe, it ignores messages going back and forth through the pipe. ERRORS
On success, an open of connld returns 0. On failure, errno is set to the following values: EINVAL A stream onto which connld is being pushed is not a pipe or the pipe does not have a write queue pointer pointing to a stream head read queue. EINVAL The other end of the pipe onto which connld is being pushed is linked under a multiplexor. EPIPE connld is being pushed onto a pipe end whose other end is no longer there. ENOMEM An internal pipe could not be created. ENXIO An M_HANGUP message is at the stream head of the pipe onto which connld is being pushed. EAGAIN Internal data structures could not be allocated. ENFILE A file table entry could not be allocated. SEE ALSO
creat(2), open(2), fattach(3C), streamio(7I) STREAMS Programming Guide SunOS 5.10 3 May 2004 connld(7M)
All times are GMT -4. The time now is 05:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy