Sponsored Content
Top Forums Shell Programming and Scripting Remove new line character and add space to convert into fixed width file Post 302753155 by Amrutha24 on Tuesday 8th of January 2013 07:46:43 AM
Old 01-08-2013
The command is working fine but when i redirect the output to a file at the actual end of record i am able to see Control M(^M) charater.

Code:
 
awk 'NR==FNR{if(length($0) > maxlen){maxlen=length($0)}next}
{printf "%-"maxlen"s\n",$0}' file1.txt file1.txt > file2.txt
 
Output file: file2.txt
123^M<2space>
12345^M
1234^M<1space>

---------- Post updated at 06:16 PM ---------- Previous update was at 06:10 PM ----------

Code:
 
awk 'BEGIN{while((getline f<FILENAME)>0){if(length(f)>l)l=length(f)}}{printf "%-"l"s\n",$0}' file

The above code gives error as
Code:
expression for `<' redirection has null string value

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

2. UNIX for Dummies Questions & Answers

Remove duplicates based on a column in fixed width file

Hi, How to output the duplicate record to another file. We say the record is duplicate based on a column whose position is from 2 and its length is 11 characters. The file is a fixed width file. ex of Record: DTYU12333567opert tjhi kkklTRG9012 The data in bold is the key on which... (1 Reply)
Discussion started by: Qwerty123
1 Replies

3. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 Replies

4. UNIX for Dummies Questions & Answers

convert # delimited text file to fixed width

Hello gurus, I have a file containing 5 columns delimited by '#' as shown in the example below: HRP1000-PLVAR#HRP1000-OTYPE#HRP1000-OBJID#HRP1000-BEGDA#HRP1000-ENDDA# 99991231#AU7129#000000000#1 PROCTER & GAMBLE# 99991231#TT4283#1000013883#21111 LAUNDRY# 99991231#TT4283#1000013884#21121 DISH... (3 Replies)
Discussion started by: chumsky
3 Replies

5. UNIX for Dummies Questions & Answers

Replace the unexpected newline char with space in a Fixed width file

Input eg: Ouput Expected. The #rd line had the unexpted new line, which need to be replaced with space. I was planing to go with checking the length of each line using awk and if the length is less than the defeined limit, (12 in above case) will replace the newline with space. ... (5 Replies)
Discussion started by: deepakwins
5 Replies

6. Shell Programming and Scripting

How to add a character after the first word/space on each line?

Hi:) I have a large file ( couple thousand lines ) and I'm trying to add a character after the first word/space on each line. eg: First line of text Second line of text Third line of text Fourth line of text Fifth line of text I'd like to accomplish: First - line of text Second... (8 Replies)
Discussion started by: martinsmith
8 Replies

7. UNIX for Beginners Questions & Answers

How do I remove leading spaces in UNIX when count of space character is not fixed? Example below-

Script showStreamsGLIS$reg.$env.ksh gives me output as below- Job Stime Etime Status ExitCode GLIS-AS-S-EFL-LOCK-B ----- ----- OI 103313880/0 GLIS-ALL-Q-EOD-FX-UPDT-1730-B ----- ----- TE 0/0 GLIS-TK-S-BWSOD-B ... (8 Replies)
Discussion started by: Tanu
8 Replies

8. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

Hi Forum. I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type. The main command in the script is: awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies

9. UNIX for Beginners Questions & Answers

Convert a fixed width file to a delimited file

Hi - this is a generic question .... is there any utility which can convert a fixed width file format to a delimited file (any given character delimited) ? (5 Replies)
Discussion started by: i4ismail
5 Replies
SC_WARTS2TEXT(1)					    BSD General Commands Manual 					  SC_WARTS2TEXT(1)

NAME
sc_warts2text -- simple dump of information contained in a warts file. SYNOPSIS
sc_warts2text [-d ip2descr-file] [file ...] DESCRIPTION
The sc_warts2text utility provides a simple dump of information contained in a sequence of warts files. The output is the same as that which would have been provided by scamper if the text output option had been chosen instead of the warts output option when the data was collected. The options are as follows: -d ip2descr-file specifies the name of a file with IP-address, description mappings, one mapping per line. See the examples section for further information. While the output of sc_warts2text is structured and suitable for initial analyses of results, the format of the output is not suitable for automated parsing and analysis as the output of sc_warts2text will change overtime with no regard to backwards compatibility. Analyses of the contents of a warts file should be made using specialised programs which link against the scamper file API. EXAMPLES
The command: sc_warts2text file1.warts file2.warts will decode and print the contents of file1.warts, followed by the contents of file2.warts. The command: gzcat file1.warts.gz | sc_warts2text will print the contents of the uncompressed file supplied on stdin. Given a set of IP-address, description pairs in a file name mappings.txt: 192.0.2.1 "foo" 192.0.2.2 "bar" then the command gzcat file1.warts.gz | sc_warts2text -d mappings.txt will print the description associated with a given destination address before each result is presented. SEE ALSO
scamper(1), sc_wartsdump(1) AUTHORS
sc_warts2text is written by Matthew Luckie <mjl@luckie.org.nz>. BSD
October 15, 2010 BSD
All times are GMT -4. The time now is 06:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy