I've been experimenting with this from the sed one-liners:
using this:
but it's producing
This is easy to explain:
This is saying apply the command (which is "N") to all lines of the form: a ":" followed by two digits at lines end. "N" combines a line with the following one, so it is easy to see, why your lines start with the dates and not the user-id.
What you want is to search for the user-id lines and then combine this with the next two lines. User-id lines are the ones without a date/time at the end, therefore we negate your search ("!" is a logical NOT):
Now lets see what we have to do with such a line: get the next two lines into our pattern space, then remove the newlines to combine the lines to one:
Now put that into a complete command:
Because your input file has a fixed structure (user-id, login timestamp on next line, logout timestamp on next) this will work and there is no need to take additional precautions, like in the oneliner example you found. It will fail, though, when this structure is disrupted.
I hope this helps.
bakunin
These 2 Users Gave Thanks to bakunin For This Post:
Hi I have used many times the various methods to append two lines together in a file.
This time I want to append the 1st line to the second and repeat for the complete file.... an example
This is the file
owns the big brown dog
joe
owns the small black dog
jim
What I want is
... (7 Replies)
I'll try explain this as best I can. Let me know if it is not clear.
I have large text files that contain data as such:
143593502 09-08-20 09:02:13 xxxxxxxxxxx xxxxxxxxxxx 09-08-20 09:02:11 N line 1 test
line 2 test
line 3 test
143593503 09-08-20 09:02:13... (3 Replies)
Hi,
I've spent some time researching for this but can't seem to find a solution. I have a file like this
1234|Test|20101111|18:00|19:00There will be multiple lines in the file with the same kind of format. For every line I need to make it this
1234|Test|20101111|18:00|19:00||create... (5 Replies)
Hello,
I have a group of text files with many lines in each file.
I need to delete all the lines in each and only leave 2 lines in each file. (3 Replies)
Hi,
I have 1000 line text file.
I need only the 1st and 8th line from every set of 10 lines, that is,
1,8,11,18,21,21,28,31,38,... lines etc into a text file.
Please let me know how I can achieve the same.
Regards,
Don (2 Replies)
Hi,
My file has the below content
Heading
1
2
3
Heading
4
5
6
I need to remove the other occurrences of first line and display other lines.
The content of first line is not static
My output should be:
Heading
1
2 (8 Replies)
Hi All,
This is very urgent, I've a data file with 1.7 millions rows in the file and the delimiter is cedilla and I need to format the data in such a way that if the NF in the next row is less than 1, it will append that value to previous line.
Any help will be appricated.
Thanks,... (17 Replies)
I have been searching and trying to come up with an awk that will perform the following on a
converted text file (original is a pdf).
1. Since the first two lines are (begin with) text they are removed
2. if $1 is a number then all text is merged (combined) into one line until the next... (3 Replies)