Sponsored Content
Top Forums Shell Programming and Scripting How to add the line to previous line in | delimited text? Post 302976928 by Narasimhasss on Friday 8th of July 2016 06:49:08 AM
Old 07-08-2016
Hi All,

Can we do like this?

First find the number of | pipe lines in the line, if the number of pipe lines are not correct then the line should be added to the previous line.

I used the below command to find the number of pipes in the line

Code:
awk -F "|" ' { print NF-1 } ' test.txt

but after I could not find the correct command if the number of pipes less than expect then needs to add this line to previous line.

Could you please help me.

Thanks,
Narasimha



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 07-08-2016 at 08:37 AM.. Reason: Added code tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search text from a file and print text and one previous line too

Hi, Please let me know how to find text and print text and its previous line. Please don't get irritated few days back I asked text and next line. I am using HP-UX 11.11 Thanks for your help. (6 Replies)
Discussion started by: kamranjalal
6 Replies

2. Shell Programming and Scripting

Delete line with match and previous line quoting/escaping problem

Hi folks, I've list of LDAP records in this format: cat cmmac.export.tmp2 dn: deviceId=0a92746a54tbmd34b05758900131136a506,ou=devices,ou=customer,ou=nl,o=upc cmmac: 00:13:11:36:a5:06 dn: deviceId=0a92746a62pbms4662299650015961cfa23,ou=devices,ou=customer,ou=nl,o=upc cmmac:... (4 Replies)
Discussion started by: tomas.polak
4 Replies

3. Shell Programming and Scripting

Sed Comparing Parenthesized Values In Previous Line To Current Line

I am trying to delete lines in archived Apache httpd logs Each line has the pattern: <ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL> This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
Discussion started by: Proteomist
1 Replies

4. UNIX for Dummies Questions & Answers

How to remove fields space and append next line to previous line.?

awk 'BEGIN{FS = "Ç"} NR == 1 {p = $0; next} NF > 1 {print p; p = $0} NF <= 1 {p = (p " " $0)} END {print p}' input.txt > output.txt This is what the input data file looks like with broken lines Code: 29863 Ç890000000 Ç543209911 ÇCHNGOHG Ç000000001 Ç055 ... (4 Replies)
Discussion started by: cumeh1624
4 Replies

5. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

6. UNIX for Dummies Questions & Answers

How to change a line of text to a comma delimited string?

Hi, Is there a one-liner that I can use to change a line of text into a comma delimited string? For example, convert user1 user2 user3 user4to user1,user2,user3,user4Currently using while read x, although got the extra comma at the end that I have to remove manually. Please... (5 Replies)
Discussion started by: newbie_01
5 Replies

7. Shell Programming and Scripting

How to add line to previous line if not a number?

Hi, I am trying to compare 2 lists. However, one of these lists has to be taken from a.pdf file. When I copy the test into a .txt document there are formatting errors which I need to correct. The document is long (~10,000 lines) so I need to script the re-formatting. Currently my file looks... (9 Replies)
Discussion started by: carlr
9 Replies

8. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies

9. Shell Programming and Scripting

Remove new line starting with a numeric value and append it to the previous line

Hi, i have a file with multiple entries. After some tests with sed i managed to get the file output as follows: lsn=X-LINK-IN0,apc=661:0,state=avail,avail/links=1/1, 00,2110597,2094790,0,81,529,75649011,56435363, lsn=TM1ITP1-AM1ITP1-LS,apc=500:0,state=avail,avail/links=1/1,... (5 Replies)
Discussion started by: nms
5 Replies

10. Shell Programming and Scripting

Add previous text when replacing comma with new line

Hi, I've got this output: # cat test2.txt TM1ITP1-TMNLSTP1 SLC00=0,SLC01=0,SLC02=0,SLC03=0 if I just use cat test2.txt | tr "," "\n" I'll end up very near to what I'm trying to achieve: TM1ITP1-TMNLSTP1 SLC00=0 SLC01=0 SLC02=0 SLC03=0 But how can i eventually add the term... (1 Reply)
Discussion started by: nms
1 Replies
wcmgr(1)							   The Webalizer							  wcmgr(1)

NAME
wcmgr - Webalizer (DNS) Cache file Manager SYNOPSIS
wcmgr [ option ... ] cache-file DESCRIPTION
wcmgr is a utility program which allows manipulation of the DNS cache files used and produced by The Webalizer. Each record in the cache file contains an IP address (either IPv4 or IPv6), a timestamp of when the entry was added to the cache, a flag to indicate if the record contains a resolved name or not, and either the same IP address or a resolved host name. All records are accessed by their IP address. RUNNING WCMGR
wcmgr was designed to be run from the Unix shell command line. This facilitates its use in shell scripts and other automated processes. A valid DNS cache file must be specified. Command line options are optional, and if none are given, the default action is to list the con- tents of the specified cache file. COMMAND LINE OPTIONS
Different functions are selected by using one or more of the following command line options. If no options are given, the default is to display the contents of the cache file to the screen (stdout). -h Display all available command line options and exit. -v Be verbose. -V Display the program version and exit. Additional program specific information will be displayed if verbose mode is also used (e.g. '-vV'), which can be useful when submitting bug reports. -a address [-n hostname] [-t0] Add a new record to the cache file. The IP address will be added to the cache file using the current time as the timestamp and with a resolved name hostname. If -t0 is specified, the record will be considered permanent, and will not be removed (during a purge) or expired. If a hostname is not specified with the -n option, then the address will be used instead, and the record will be flagged as unresolved. -c Create a new cache file. If used alone, this option will create a new, empty cache file. If used with the import option, a new cache file will be created before importing the data. An error will occur if the file cache-file already exists. -d address Delete a record from the cache file using the specified address. -f address Find and display information for address from the cache file. A single line similar to that produced by the -l option will be dis- played unless verbose mode is enabled, in which case a more detailed listing will be produced. -i name [-c] Import data into the cache file from the file name. The import file must be a valid tab delimited text file, such as that created by the export option. If the imported data contains records already present in the cache file, those records will be overwritten by the imported data. The cache file must exist unless the -c option is specified, in which case, a new cache file will be created for the imported data. -l List the contents of the cache file. This is the default action of the program, so does not necessarily need to be specified. If verbose mode is enabled, a report title, column headers and summary totals will also be displayed. -p num Purge the cache file of entries older than num days. If num is not specified, then a default of 7 days will be used. if verbose mode is enabled, each purged record will be printed and the total number of purged records will be displayed. -s [-t num] Display cache file information/statistics. If a TTL value (in days) is specified using the -t option, it will be used to calculate how many records are older than num days, otherwise, the default value of 7 days will be used. -n name Specify the name to use as the resolved hostname when adding records to the cache. -t num Time to live (TTL) value. If used along with the -p (purge) option, it specifies how many days a record will remain valid. Any record that is older than num days is considered expired and will be purged. If used with the -a (add) option, a zero value will cause the record to be considered permanent. -x name Export data from a cache file to a tab delimited text file named name. If the text file name exists, it will be overwritten. BUGS
Please report bugs to the author. COPYRIGHT
Copyright (C) 1997-2011 by Bradford L. Barrett. Distributed under the GNU GPL. See the files "COPYING" and "Copyright", supplied with all distributions for additional information. AUTHOR
Bradford L. Barrett <brad at mrunix dot net> Version 1.00 12-Jul-2008 wcmgr(1)
All times are GMT -4. The time now is 02:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy