sed and awk for long lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sed and awk for long lines
# 8  
Old 10-03-2014
Quote:
Originally Posted by vbe
Have you looked at the man pages of dd? What OS are you on? I used to do things like that on HP-UX years ago... specially when importing/exporting files to mainframes...
I'm on HP-UX
# 9  
Old 10-03-2014
Quote:
Originally Posted by uxusr
Tried the below
awk {printf "%-4000s", $0} Temp_test1.dat
. . .
This is not coreutils' printf.
# 10  
Old 10-03-2014
Quote:
Originally Posted by RudiC
This is not coreutils' printf.
Sorry, so lost here.
Do you mean I'm not supposed to use this?
# 11  
Old 10-03-2014
Quote:
Originally Posted by uxusr
Sorry, so lost here.
Do you mean I'm not supposed to use this?
You said:
Code:
awk {printf "%-4000s", $0} Temp_test1.dat

failed. We already knew that it would. If your awk can't handle long lines; the awk printf() function can't handle long lines either. But, the printf utility can probably handle long lines:
Code:
while IFS='' read -r x
do      printf '%-4000s' "$x"
done < inputfile.dat > outputfile.dat

or:
Code:
dd if=inputfile.dat of=outputfile.dat cbs=4000 block

Note that both of these will convert variable length, newline terminated lines into fixed length records with no line terminators. If you want fixed length LINES instead of RECORDS, use the while loop in your shell and change the printf format string to '%-4000s\n'.
# 12  
Old 10-03-2014
Please enter $ printf "%-4000s", $variable at the command prompt (no awk!)
# 13  
Old 10-03-2014
Here is why you have an awk problem:
There is a system configuration parameter LINE_MAX.

On some systems LINE_MAX is 2048 bytes. This limit applies to core unix utilities and tells them what the longest possible line in files is allowed. awk obeys this limit.

Code:
getconf

command will show you other limits, as well. Like the max number of bytes you can pass in a variable as an argument. Consider taking a peek at what it does for you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join lines using sed or awk

Hi, I have text file that looks like this: blabla bla PATTERN LINE1 LINE2 bla bla bla PATTERN LINE1 LINE2 bla PATTERN LINE1 LINE2 bla (9 Replies)
Discussion started by: hench
9 Replies

2. Shell Programming and Scripting

awk - sed :Help Getting next lines data .

Experts, Can you please help how to get the output that are written just below "bad" calls badcalls nullrecv 439486 54 0 badlen xdrcall dupchecks ... (6 Replies)
Discussion started by: rveri
6 Replies

3. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

4. Shell Programming and Scripting

Sed/awk to delete single lines that aren't touching other lines

Hello, I'm trying to figure out how to use sed or awk to delete single lines in a file. By single, I mean lines that are not touching any other lines (just one line with white space above and below). Example: one two three four five six seven eight I want it to look like: (6 Replies)
Discussion started by: slimjbe
6 Replies

5. Shell Programming and Scripting

Long lines in test.awk

I have a awk script called test.awk which I run using awk -f test.awk file1.txt > file2.txt I am doing a long print statement and want to put it in separate lines Do I need a '/' at the end or not????? Should it be like this print... (12 Replies)
Discussion started by: kristinu
12 Replies

6. Shell Programming and Scripting

How to remove lines before and after with awk / sed ?

Hi guys, I need to remove the pattern (ID=180), one line before and four lines after. Thanks. (5 Replies)
Discussion started by: ashimada
5 Replies

7. Shell Programming and Scripting

Add lines with sed or awk

I want to get an output from the input as below: Input: ASDDS14 RXOTX-39-8 AB0991C TRY1900 AEDFS12 RXOTX-39-9 TK0991C TRY800 HSVDS11 RXOTX-389-10 LG0991C TRY1900 BSDDS09 RXOTX-394-0 AA0066A TRY800 OUTPUT: ASDDS14 RXOTS-39-8-0 AB0991C TRY1900... (2 Replies)
Discussion started by: aydj
2 Replies

8. Shell Programming and Scripting

Replacing or removing a long list of pattern by using awk or sed

Input: >abc|123456|def|EXIT| >abc|203456|def|EXIT2| >abc|234056|def|EXIT3| >abc|340056|def|EXIT4| >abc|456000|def|EXIT5| . . . Output: def|EXIT| def|EXIT2| def|EXIT3| def|EXIT4| def|EXIT5| . . My try code: (9 Replies)
Discussion started by: patrick87
9 Replies

9. Shell Programming and Scripting

Manipulate lines with sed/awk

Hey All, I need to reorganize a file's text. Here is the source: host John_Doe filename "config.cfg"; hardware ethernet 98:10:3d:13:8f:98; fixed-address 10.10.10.29; } host Jane_Doe filename "config.cfg"; hardware ethernet 98:13:11:fd:5a:57; fixed-address 10.10.5.24; } host... (2 Replies)
Discussion started by: TheBigAmbulance
2 Replies

10. Shell Programming and Scripting

line too long using awk or sed or tr

Goodmorning, I have MKS Toolkit (K-Shell) running on a windows server. On it I have a c program that in a true unix environment works fine, but here it adds an extra '0000000000000016000A' in various places in the file that the c program produces that I need to remove. Here is what the file... (3 Replies)
Discussion started by: philplasma
3 Replies
Login or Register to Ask a Question