Remove newline character from column spread over multiple lines in a file
Hi,
I came across one issue recently where output from one of the columns of the table from where i am creating input file has newline characters hence, record in the file is spread over multiple lines. Fields in the file are separated by pipe (|) delimiter. As header will never have newline character, I am trying to compare if other rows have same number of fields as that of header and if number of fields in particular row is less than number of fields in header line then I am removing newline character at the end of the line. I was able to do this for row spread over two lines but, I am not getting correct output for lines spread over multiple lines.
Below is test input file and expected output file -
Input file -
Expected output file -
Below code worked for row spread over two lines -
I also tried below code but it is not giving expected output -
Can someone please help me in this?
Below an example of what I mean. The first attempt does what I want; the second doesn't, because bash assumes a line break means the end of an individual "command unix". Is there some way that I can convince bash to parse out, eg, to the closing parenthesis?
I'm thinking this would allow for... (1 Reply)
I have several huge files wich contains oracle table creation scripts as follows:
I would need to remove the pattern colored in red above. Any sed/awk/pearl code will be of much help.
Thanks (2 Replies)
Hi All,
I have named a file with current date,time and year as follows:
month=`date | awk '{print $2}'`
date=`date | awk '{print $3}'`
year=`date | awk '{print $6}'`
time=`date +%Hh_%Mm_%Ss'`
filename="test_"$month"_"$date"_"$year"_"$time".txt"
> $filename
The file is created with a... (2 Replies)
Hi All,
We append the output of a file's size in a file. But a newline character is appended after the variable.
Pls help how to clear this.
filesize=`ls -l test.txt | awk `{print $5}'`
echo File size of test.txt is $filesize bytes >> logfile.txt
The output we got is,
File size of... (4 Replies)
Hi All,
I have 5000 records like this
Request_id|Type|Status|Priority|Ticket Submitted Date and Time|Actual Resolved Date and Time|Current Ticket Owner Group|Case final Ticket Owner Group|Customer Severity|Reported Symptom/Request|Component|Hot Topic|Reason for Missed SLA|Current Ticket... (2 Replies)
Hello all,
first off great forum.
Now for my little problem.
Using RHEL 5.4 and awk. Been doing code since a few month. So just starting.
My problem is handeling data on multiple lines.
{
if ($1 != LASTKEY && h ~ /.*\/s_fr_/) {
checkgecos( h, h )
h=""
... (2 Replies)
Hi,
In my file, I have '\n' characters inside a single record. Because of this, a single records appears in many lines and looks like multiple records. In the below file.
File 1
====
1,nmae,lctn,da\n
t
2,ghjik,o\n
ut,de\n
fk
Expected output after the \n removed
File 2
=====... (5 Replies)
hi i am having delimited .dat file having content like below.
test.dat(5 line of records)
======
PT2~Stag~Pt2 Stag Test.
Updated~PT2 S T~Area~~UNCEF R20~~2012-05-24 ~2014-05-24~~
PT2~Stag y~Pt2 Stag Test.
Updated~PT2 S T~Area~METR~~~2012-05-24~2014-05-24~~test
PT2~Pt2 Stag Test~~PT2 S... (4 Replies)
Hi all..
I have a text file which looks like below:
abcd
efgh
ijkl
(blank space)
I need to remove only the last (blank space) from the file. When I try wc -l the file name,the number of lines coming is 3 only, however blank space is there in the file.
I have tried options like... (14 Replies)
I have a file which comes every day and the file data look's as below.
Vi abc.txt
a|b|c|d\n
a|g|h|j\n
Some times we receive the file with only a new line character in the file like
vi abc.txt
\n (8 Replies)
Discussion started by: rak Kundra
8 Replies
LEARN ABOUT OSF1
paste
paste(1) General Commands Manual paste(1)NAME
paste - Joins corresponding lines of several files or subsequent lines in one file
SYNOPSIS
paste [-d list] [-s] file...
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
paste: XCU5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
OPTIONS
Replaces the delimiter that separates lines in the output (tab by default) with one or more characters from list. If list contains more
than one character, then the characters are repeated in order until the end of the output. In parallel merging, the lines from the last
file always end with a newline character, instead of one from list.
The following special characters can be used in list: Newline character Tab Backslash Empty string (not a null character) [Tru64
UNIX] An extended character
You must quote characters that have special meaning to the shell. Merges all lines from each input file into one line of output
(serial merging). Using this option, the paste command merges all lines in the first input file forcing a newline before at the
end. The command then continues with the next input file, continuing in the same manner until all input files have been completed.
A tab separates the input lines unless you use the -d option. Regardless of the list, the last character of the output is a newline
character.
OPERANDS
The name of an input file. You may specify up to 12 files, including hyphens.
If you specify a -, paste reads standard input recursively, one line for each -.
DESCRIPTION
Specifying the -d option or no options causes the paste command to treat each file as a column, joining them horizontally with a tab char-
acter by default (parallel merging).
Using the -s option, the paste command combines all lines of each input file into one output line (serial merging). These lines are joined
with the tab character by default.
Output lines can be any length.
[Tru64 UNIX] The output of pr -t -m is similar to the output produced by the paste command, but pr with its options creates extra spaces,
tabs, and lines for an enhanced page layout.
RESTRICTIONS
If the -s option is not used, it is an error if any specified file cannot be opened.
EXIT STATUS
The following exit values are returned: Successful completion. An error occurred.
EXAMPLES
To paste several columns of data together, enter: paste names places dates > npd
This creates a file named npd that contains the data from names in one column, places in another, and dates in a third. The columns
are separated by tab characters.
File npd then contains:
rachel New York 28 February jerzy Warsaw 27 April mata Nairobi 21 June michel
Boca Raton 27 July segui Managua 18 November
A tab character separates the name, place, and date on each line. To separate the columns with a character other than a tab (sh
only), enter: paste -d"!@" names places dates > npd
This alternates the apostrophe (!) and the at sign (@) as the column separators. If names, places, and dates are the same as in
Example 1, then npd contains:
rachel!New York@28 February jerzy!Warsaw@27 April mata!Nairobi@21 June michel!Boca Raton@27 July segui!Managua@18 November To dis-
play the standard input in multiple columns, enter: ls | paste - - - -
This lists the current directory in four columns. Each hyphen (-) tells the paste command to create a column containing data read
from the standard input. The first line is put in the first column, the second line in the second column, ... and then the fifth
line in the first column, and so on.
This is equivalent to ls | paste -d"
" -s-
which fills the columns across the page with subsequent lines from the standard input. The -d
defines the character to
insert after each column: a tab character ( ) after the first three columns, and a newline character (
) after the fourth. Without
the -d option, paste -s - displays all of the input as one line with a tab between each column. To merge the lines of the file
names above into one output line, enter: paste -s names
This results in: rachel jerzy mata michel segui
ENVIRONMENT VARIABLES
The following environment variables affect the execution of paste: Provides a default value for the internationalization variables that are
unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari-
ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value,
overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as opposed to multibyte characters in arguments and input files). Determines the
locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the
processing of LC_MESSAGES.
SEE ALSO
Commands: cut(1), grep(1), fold(1), join(1), pr(1)
Standards: standards(5)paste(1)