Sponsored Content
Top Forums Shell Programming and Scripting Program to combine two lines in a file on checking the first character of each line Post 302967690 by RudiC on Friday 26th of February 2016 10:03:37 AM
Old 02-26-2016
Try also
Code:
awk '{sub (/,+$/,_); printf "%s%s", /^[0-9]+/?XS:"", $0; XS = RS} END {printf RS}' file
5,1,32784506,6/3/2015,6/3/2015,9:15:22,6/3/2015,9:15:34,0,16,0,ValidateClass [TGWFTRNBO]]
6,1,32784506,6/3/2015,6/3/2015,9:15:22,6/3/2015,9:15:34,0,16,0,ValidateClass [TGWFTRNBO]]
7,1,32784506,6/3/2015,6/3/2015,9:15:22,6/3/2015,9:15:34,0,16,0,ValidateClass [TGWFTRNBO]]The operative account
10,1,32784506,6/3/2015,6/3/2015,9:15:22,6/3/2015,9:15:34,0,16,0,ValidateClass [TGWFTRNBO]]

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine multiple lines in single line

This is related to one of my previous post but now with a slight difference: I need the "Updated:" to be in one line as well as the "Information:" on one line as well. These are in multiple lines right now as seen below. These can have 2 or more lines that needs to be in one line. System name:... (8 Replies)
Discussion started by: The One
8 Replies

2. Shell Programming and Scripting

Combine multiple unique lines from event log text file into one line, use PERL or AWK?

I can't decide if I should use AWK or PERL after pouring over these forums for hours today I decided I'd post something and see if I couldn't get some advice. I've got a text file full of hundreds of events in this format: Record Number : 1 Records in Seq : ... (3 Replies)
Discussion started by: Mayday22
3 Replies

3. Shell Programming and Scripting

Checking ^M character in file

i have the file <infile> with ^M charactrer. i just wnt to know through script whether the file have ^M character or not. Please let me know the script steps to check the same. Thanks in Advance Ganesh. (3 Replies)
Discussion started by: Ganesh L
3 Replies

4. Shell Programming and Scripting

Combine multiple lines into single line

Hi All , I have a file with below data # User@Host: xyz @ # Query_time: t1 Lock_time: t2 Rows_sent: n1 Rows_examined: n2 SET timestamp=1396852200; select count(1) from table; # Time: 140406 23:30:01 # User@Host: abc @ # Query_time: t1 Lock_time: t2 Rows_sent: n1 Rows_examined:... (6 Replies)
Discussion started by: rakesh_411
6 Replies

5. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

6. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

7. UNIX for Dummies Questions & Answers

Need to combine two lines in a file based on first character of each line in a file

Hi, I have a requirement where I need to combine two lines in a file based on first character of each line in a file. Please find the sample content of the file below: Code: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

8. UNIX for Advanced & Expert Users

Need to combine two lines in a file based on first character of each line in a file

Hi, I have a requirement where I need to combine two lines in a file based on first character of each line in a file. Please find the sample content of the file below: Code: _______________________ 5, jaya, male, 4-5-90, single smart 6, prakash, male, 5-4-84, married fair 7, raghavi,... (1 Reply)
Discussion started by: jayaP
1 Replies

9. Shell Programming and Scripting

awk to remove lines that do not start with digit and combine line or lines

I have been searching and trying to come up with an awk that will perform the following on a converted text file (original is a pdf). 1. Since the first two lines are (begin with) text they are removed 2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)
Discussion started by: cmccabe
3 Replies

10. UNIX for Beginners Questions & Answers

awk with sed to combine lines and remove specific odd # pattern from line

In the awk piped to sed below I am trying to format file by removing the odd xxxx_digits and whitespace after, then move the even xxxx_digit to the line above it and add a space between them. There may be multiple lines in file but they are in the same format. The Filename_ID line is the last line... (4 Replies)
Discussion started by: cmccabe
4 Replies
adjust(1)						      General Commands Manual							 adjust(1)

NAME
adjust - simple text formatter SYNOPSIS
column] tabsize] [files]... DESCRIPTION
The command is a simple text formatter for filling, centering, left and right justifying, or only right justifying text paragraphs, and is designed for interactive use. It reads the concatenation of input files (or standard input if none are given) and produces on standard output a formatted version of its input, with each paragraph formatted separately. If is given as an input filename, reads standard input at that point (use as an argument to separate from options.) reads text from input lines as a series of words separated by space characters, tabs, or newlines. Text lines are grouped into paragraphs separated by blank lines. By default, text is copied directly to the output, subject only to simple filling (see below) with a right mar- gin of 72, and leading spaces are converted to tabs where possible. Options The command recognizes the following command-line options: Do not convert leading space characters to tabs on output; (output contains no tabs, even if there were tabs in input). Center text on each line. Lines are pre- and post-processed, but no filling is performed. Justify text. After filling, insert spaces in each line as needed to right justify it (except in the last line of each paragraph) while keeping the justified left margin. After filling text, adjust the indentation of each line for a smooth right margin (ragged left margin). Set the right fill margin to the given column number, instead of 72. Text is filled, and optionally right justified, so that no output line extends beyond this column (if possible). If is given, the current right margin of the first line of each paragraph is used for that and all subsequent lines in the para- graph. By default, text is centered on column 40. With the option sets the middle column of the centering "window", but auto- sets the right side as before (which then determines the center of the "window"). Set the tab size to other than the default (eight columns). Only one of the and options is allowed in a single command line. Details Before doing anything else to a line of input text, first handles backspaces, rubbing out preceding characters in the usual way. Next, it ignores all nonprintable characters except tab. It then expands all tabs to spaces. For simple text filling, the first word of the first line of each paragraph is indented the same amount as in the input line. Each word is then carried to the output followed by one space. "Words" ending in terminal_character[quote][closing_character] are followed by two spa- ces, where terminal_character is any of or quote is a single closing quote or double-quote character (), and close is any of or Here are some examples: does not place two spaces after a pair of single closing quotes following a terminal_character). starts a new output line whenever adding a word (other than the first one) to the current line would exceed the right margin. understands indented first lines of paragraphs (such as this one) when filling. The second and subsequent lines of each paragraph are indented the same amount as the second line of the input paragraph if there is a second line, else the same as the first line. also has a rudimentary understanding of tagged paragraphs (such as this one) when filling. If the second line of a paragraph is indented more than the first, and the first line has a word beginning at the same indentation as the second line, the input column position of the tag word or words (prior to the one matching the second line indentation) is preserved. Tag words are passed through without change of column position, even if they extend beyond the right margin. The rest of the line is filled or right justified from the position of the first nontag word. When is given, uses an intelligent algorithm to insert spaces in output lines where they are most needed, until the lines extend to the right margin. First, all one space word separators are examined. One space is added to each separator, starting with the one having the most letters between it and the preceding and following separators, until the modified line reaches the right margin. If all one space separators are increased to two spaces and more spaces must be inserted, the algorithm is repeated with two space separators, and so on. Output line indentation is held to one less than the right margin. If a single word is larger than the line size (right margin minus indentation), that word appears on a line by itself, properly indented, and extends beyond the right margin. However, if is used, such words are still right justified, if possible. If the current locale defines class names and (see iswctype(3C)), formats the text in accordance with the character classification and mar- gin settings (see and options). EXTERNAL INFLUENCES
Environment Variables provides a default value for the internationalization variables that are unset or null. If is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, will behave as if all internationalization variables are set to "C". See environ(5). If set to a nonempty string value, overrides the values of all the other internationalization variables. determines the interpretation of text as single and/or multi-byte characters, the classification of characters as printable, and the char- acters matched by character class expressions in regular expressions. determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informa- tive messages written to standard output. determines the location of message catalogs for the processing of International Code Set Support Single- and multi-byte character code sets are supported. DIAGNOSTICS
complains to standard error and later returns a nonzero value if any input file cannot be opened (it skips the file). It does the same (but quits immediately) if the argument to or is out of range, or if the program is improperly invoked. Input lines longer than are silently split (before tab expansion) or truncated (afterwards). Lines that are too wide to center begin in column 1 (no leading spaces). EXAMPLES
This command is useful for filtering text while in vi(1). For example, reformats the rest of the current paragraph (from the current line down), evening the lines. The command: (where denotes control characters) sets up a useful "finger macro". Typing (Ctrl-X) reformats the entire current paragraph. is a simple way to break text into separate words without whitespace, except for tagged-paragraph tags. WARNINGS
This program is designed to be simple and fast. It does not recognize backslash to escape whitespace or other characters. It does not recognize tagged paragraphs where the tag is on a line by itself. It knows that lines end in newline or null, and how to deal with tabs and backspaces, but it does not do anything special with other characters such as form feed (they are simply ignored). For complex opera- tions, standard text processors are likely to be more appropriate. This program could be implemented instead as a set of independent programs, fill, center, and justify (with the option). However, this would be much less efficient in actual use, especially given the program's special knowledge of tagged paragraphs and last lines of para- graphs. AUTHOR
was developed by HP. SEE ALSO
nroff(1). adjust(1)
All times are GMT -4. The time now is 09:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy