Sponsored Content
Top Forums Shell Programming and Scripting refine awk command in replacing carriage return Post 302544490 by agathaeleanor on Thursday 4th of August 2011 03:18:32 AM
Old 08-04-2011
refine awk command in replacing carriage return

Hi,

need your help in below,I have 4 types of file need to be processed so that it will replace carriage return in Remarks column with <:::>
Remarks column position may varies in different types of file.

sample file:
Code:
col1|col2|col3|col4|col5|col6|col7|Remarks|col9|col10
A_1|11|12|13|14|15|16
|Testing 
remarks|18|19
A_2|21|22|23|24|25|26|Testing
 
remarks|28|29

desired output:
Code:
col1|col2|col3|col4|col5|col6|col7|Remarks|col9|col10
A_1|11|12|13|14|15|16|Testing:::remarks|18|19
A_2|21|22|23|24|25|26|Testing:::remarks|28|29

tukuyomi helps in this requirement with below script
Code:
awk -F\| 'FNR==1{n=NF}NF<n{l=$0;getline;$0=l":::"$0}1'

but it is not work when the carriage return happen twice (with empty row) and the carriage return is happen before a pipe <|>

Your help is much appreciate

Last edited by radoulov; 08-04-2011 at 06:58 AM.. Reason: Code tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dont want carriage return

I have observed with print & echo, they produce carriage return <CR> or newline, after they display string next to them. Is there anyway to avoide these <CR> after the intended string is displayed? (3 Replies)
Discussion started by: videsh77
3 Replies

2. Shell Programming and Scripting

Carriage return on long awk operation

hello all I have long awk function that doing manipulations on text file but when I write the out put to new text file I have carriage return between 2 print commands How can I avoid this ? Here is my awk : echo $f | awk... (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

tcl command to supply a carriage return

I have a java program that runs on a unix server that prompts the user for input and provides a default value to the user. So it does something like this: Enter source server name <source_server_name>: Enter target server name <target_server_name>: I just hit enter to take the default... (1 Reply)
Discussion started by: progkcp
1 Replies

4. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

5. Shell Programming and Scripting

Refine awk

Hi The commnad shows the following o/p df -kh /abc/bds/ |awk {'print$5'} capacity 87% I want the o/p as 87 only Can we achieve this using a oneliner of sorts NB : Code tags not working with my google chrome , So wasn't able to place code in tags . Pls dont penalise :-) Thanks (6 Replies)
Discussion started by: ultimatix
6 Replies

6. Shell Programming and Scripting

Why sed command deletes last line in a file if no carriage return?

Hi I am using sed command to make SCORE=somevalue to SCORE=blank in a file. Please see the attached lastline.txt file. After executing the below command on the file, it removes the last line. cat lastline.txt | sed 's/SCORE=.*$/SCORE=/g' > newfile.txt Why does sed command remove the... (3 Replies)
Discussion started by: ashok.k
3 Replies

7. Shell Programming and Scripting

Awk to remove carriage return from 65th field

Hi, I have a pipe delimited file. There are around 700 columns in the file. The 65th column has carriage return which is causing read issue with our ETL process. I would like to replace the new line characters in 65th field with "nothing" i have return the following code and need help to... (7 Replies)
Discussion started by: pinnacle
7 Replies

8. Shell Programming and Scripting

Substitute \n with carriage return

Hello all, I've a flat file in the following format: AB\001\CDED\001\ABC\001\nEG\001\HIJF\001\EFG\001\nHI\003\HIUL\003\HIJ\003 And I want to substitute \n with the carriage return. Any help is appreciated! Regards, - Seth (8 Replies)
Discussion started by: sethmj
8 Replies

9. Shell Programming and Scripting

Losing carriage return (X0D) after running awk command

Hi Forum. I'm running the following awk command to extract the suffix value (pos 38) from the "AM00" record and append to the end of the "AM01" record. awk 'substr($0,13,4)=="AM00" {SUFFIX = substr($0,38,2)} substr($0,13,4)=="AM01" {$0 = $0 SUFFIX} 1' before.txt > after.txt Before.txt:... (2 Replies)
Discussion started by: pchang
2 Replies

10. UNIX for Beginners Questions & Answers

awk Command to add Carriage Return and Line Feed

Hello, Can someone please share a Simple AWK command to append Carriage Return & Line Feed to the end of the file, If the Carriage Return & Line Feed does not exist ! Thanks (16 Replies)
Discussion started by: rosebud123
16 Replies
DB2_FIELD_NUM(3)							 1							  DB2_FIELD_NUM(3)

db2_field_num - Returns the position of the named column in a result set

SYNOPSIS
int db2_field_num (resource $stmt, mixed $column) DESCRIPTION
Returns the position of the named column in a result set. PARAMETERS
o $stmt - Specifies a statement resource containing a result set. o $column - Specifies the column in the result set. This can either be an integer representing the 0-indexed position of the column, or a string containing the name of the column. RETURN VALUES
Returns an integer containing the 0-indexed position of the named column in the result set. If the specified column does not exist in the result set, db2_field_num(3) returns FALSE. SEE ALSO
db2_field_display_size(3), db2_field_name(3), db2_field_precision(3), db2_field_scale(3), db2_field_type(3), db2_field_width(3). PHP Documentation Group DB2_FIELD_NUM(3)
All times are GMT -4. The time now is 09:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy