awk concatenate every line of a file in a single line
I have several hundreds of tiny files which need to be concatenated into one single line and all those in a single file. Some files have several blank lines. Tried to use this script but failed on it.
It would've been nice to know if those did what you wanted. If they don't, neither will the same thing written in awk!
ORS controls the output record separator, which is a newline by default. Setting it blank tells it to print nothing between records, so it'll squeeze it all together. Then at the very end, print one newline, since most things need a newline on the very end to acknowledge it as a line.
It would've been nice to know if those did what you wanted. If they don't, neither will the same thing written in awk!
ORS controls the output record separator, which is a newline by default. Setting it blank tells it to print nothing between records, so it'll squeeze it all together. Then at the very end, print one newline, since most things need a newline on the very end to acknowledge it as a line.
Sorry can't test cat & tr. I am using windowz
Have tried your code but am still in trouble with the FILENAME in front of each line. I also changed {$1=$1} into {$0=$0} and wondering if this makes it faster?
Have tried your code but am still in trouble with the FILENAME in front of each line. I also changed {$1=$1} into {$0=$0} and wondering if this makes it faster?
Either way is a complete no-op. The only point of it is to inform awk that the data has changed, so that it should translate the newlines into the output record separator of nothing. I'd expect both ways to use nearly no time...
It's always better to show what you want than to post code for a routine which doesn't do what you want; broken code can't be used to show what you do want. Now that I understand your needs a little better:
Doing an explicit print means not needing to do $1=$1 to get translation. We print exactly what we want instead -- sometimes that's easier than manipulating $0 into what you want printed, and sometimes it's not...
The $1 before the block avoids processing blank lines.
FILENAME is never set in the BEGIN block. BEGIN means the beginning of the program, not the beginning of the line -- and having not yet read any data, there's no FILENAME set inside...
This code produces the FILENAME for every line in the input File. (at least in gawk).
Quote:
FILENAME is never set in the BEGIN block. BEGIN means the beginning of the program, not the beginning of the line -- and having not yet read any data, there's no FILENAME set inside...
example of problem:
when I echo "$e" >> /home/cogiz/file.txt
result prints to file as:AA
BB
CC
I need it to save to file as this:AA BB CC
I know it's probably something really simple but any help would be greatly appreciated.
Thank You.
Cogiz (7 Replies)
Hi,
Do anybody experience how to concatenate multiple line into one line by using awk or perl command?
Input file:
>set1
QAWEQRQ@EWQEASED
ASDAEQW
QAWEQRQTQ
ASRFQWRGWQ
From the above Input file, it got 5 lines
Desired output file:
>set1... (6 Replies)
Hello to all,
I'm new to perl, I have input file that contains the string below:
315350535ff450000014534130101ff4500ff45453779ff450ff45545f01ff45ff453245341ff4500000545000This string has as line separator "ff45". So, I want to print each line but the code below is not working.
perl -pe '... (2 Replies)
Hi All,
I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end.
Before:-
File Name:- File1.dat
102 121340560... (10 Replies)
Hi,
My awk program is failing. I figured out using command
od -c filename
that the last line of the file doesnt end with a new line character.
Mine is an automated process because of this data is missing.
How do i handle this?
I want to append new line character at the end of last... (2 Replies)
I need a script to process a huge single line text file:
The sample of the text is:
"forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Sample input (line feed indicated by )
---------------
The red fox jumped
over the brown fence of the
red hous
He then went into the
orchard
---------------
Desired Output
---------------
The red fox jumped over the brown fence of the red house
He then went into the orchard (11 Replies)
Hi, I have a noob question . Can someone help me how to concatenate line by line using this variables?
var1:
Apple|
Banana|
var2:
Red
Yellow
then how can I concatenate both line by line? in which the result would be:
Apple|Red
Banana|Yellow
just to generate a row result i was... (6 Replies)
Hi All,
i have a zip file like the format
794051400123|COM|24|0|BD|R|99.98
794051413727|COM|11|0|BD|R|28.99
794051415622|COM|23|0|BD|R|28.99
883929004676|COM|0|0|BD|R|28.99
794051400123|MOM|62|0|BD|R|99.98
794051413727|MOM|4|0|BD|R|28.99
794051415622|MOM|80|0|BD|R|28.99
... (30 Replies)