I have a file containing many records delimited by pipe (|).
Each record should contain 17 columnns/fields. there are some fields having fields less than 17.So i am extracting those records to a file using the below command
Then i am concatenating all lines in feedfilebadrecs.txt to one single line.
tr -d '\n' < feedfilebadrecs.txt
but its not working. The concatenation is not happening.I have tried concatenating with other commands like paste,sed , awk etc. but not working(giving some random line as output from the input file)
I applied these commands for concatenating on some other manually created files and its working .
I am not able to understand why concatenation is not happening on dynamically created file using awk.
What operating system are you using?
How many lines are you concatenating?
After concatenating those lines, how long is your single output line supposed to be?
How have you determined that the concatenation is not working?
What output do you get if you run the commands:
1)I am using HP-UX
2) Depends on the requirement, right now I am concatenating only few lines as shown in the screen shot.
3)The single output line can be as long as 300 characters.
4)Its giving only single line from a group of lines in the input file as shown in the screenshot
5)Please see the screen shot
Your problems are that you have a DOS file that you're working on with UNIX utilities (get rid of the carriage return characters and you would get something closer to what you were expecting), and you want to join pairs of truncated lines from feedfile.txt ; not all truncated lines.
Try (untested since you haven't given us a usable copy of feedfile.txt ):
awk '
BEGIN { FS = OFS = "|" }
{ sub(/\r/, "") }
NF < 17 { $1 = save $1; save = $0 }
NF >= 17 { print; save = "" }
' feedfile.txt > fixed_feedfile.txt
please find the screenshot.
I executed your command,now awk output is all records having number of fields as 17. My aim is to extract all records which are less than 17 fields into a new file and then concatenate all lines in that new file.
Also please find the attached feed file.
which I would think would be more useful than stripping out the 3 lines that were reconstructed from the partial lines in your input file and producing a single, concatenated, partial line containing 49 (not 51) fields (with no trailing <newline> character).
The space shown in the middle of the text shown in red above is because there is a space before the carriage return character in the 7th line in feedfile.txt which can be seen in the output from the cat -vet feedfile.txt you showed us in post #5 in this thread.