Please some help over here. I have a Sales.txt file containing info in blocks for
every sold product in the pattern showed below (only for 2 products).
NEW BLOCK
SALE DATA
PRODUCT SERIAL
79833269999 146701011945004
.Some other data
.Some other data
.Some other data
SALE SERIAL SALE NUMBER
7-4324990101 4324990101
STORE NUMBER
7-43212
END OF BLOCK
NEW BLOCK
SALE DATA
PRODUCT SERIAL
79806743123 1598670108411112
.Some other data
.Some other data
.Some other data
SALE SERIAL SALE NUMBER
7-4324995448 4324995448
STORE NUMBER
7-43213
END OF BLOCK
I�ve used awk for basic things, but this is beyond my knowledge. I�d like to extract only the number below the word "PRODUCT" and its respective number below "SALE SERIAL" and store the processed data in a new file.
For the data blocks above the desired result would be.
79833269999 7-4324990101
79806743123 7-4324995448
Somebody could help me with this issue please. Grateful for any help or suggestion.
How can I get only the number in first column below every word to see the info as follow: (I mean, leaving the numbers in red in the same line and erasing the other ones)
79833269999 7-4324990101 -->numbers extracted from block 1
79806743123 7-4324995448 -->numbers extracted from block 2
Now I have the wanted result, many thanks jpradley for your help and time, with your tips and after several tests I�ve found a code that works for my request. There are 3 different commands that I put in a .sh file, but I�m not sure how to join them in one command in order to write "awk" only once.
Hi, I'm newby to scripting. Thanks in advance for your input.. I have a flat file like below:
"Mon Jan 7 11:32:25 EST 2008",
291
"Mon Jan 7 12:01:00 EST 2008",
291
"Mon Jan 7 18:01:00 EST 2008",
318
"Tue Jan 8 00:01:00 EST 2008",
357
"Tue Jan 8 06:01:00 EST 2008",
352
"Tue Jan 8 12:01:00 EST 2008",
388
"Tue Jan 8 18:01:00 EST 2008",
387
"Wed Jan 9 00:01:00 EST 2008",
387
"Wed Jan 9 06:01:00 EST 2008",
406
"Wed Jan 9 12:01:00 EST 2008",
403
"Wed Jan 9 18:01:00 EST 2008",
406
"Thu Jan 10 00:01:00 EST 2008",
414
"Thu Jan 10 06:01:00 EST 2008",
I need to merge line 1 and 2, then 3 and 4, to make it become:
"Mon Jan 7 11:32:25 EST 2008", 291
"Mon Jan 7 12:01:00 EST 2008",291
"Mon Jan 7 18:01:00 EST 2008",318
"Tue Jan 8 00:01:00 EST 2008",357
"Tue Jan 8 06:01:00 EST 2008",352
"Tue Jan 8 12:01:00 EST 2008",388
"Tue Jan 8 18:01:00 EST 2008",387
"Wed Jan 9 00:01:00 EST 2008",387
"Wed Jan 9 06:01:00 EST 2008",406
"Wed Jan 9 12:01:00 EST 2008",403
"Wed Jan 9 18:01:00 EST 2008",406
"Thu Jan 10 00:01:00 EST 2008",414
"Thu Jan 10 06:01:00 EST 2008",.......
Many thanks Franklin52, I�ve learned several things through this question.
Thanks for your contribution and take some of your time to share what you know.
Hi flyingfish,
Part of my problem was exactly you�re asking.
I got a sample code over there that does what you want; I mean, put odd lines in column 1
and even lines in column 2. I�m not completely sure how it works, but it works
Try with:
(To print in display the processed data)
awk 'ORS = NR%2 ? " " : "\n"' Source.txt
or
(To send the processed data from Source.txt to the file Destination.txt)
First, don't hijack another ones thread but start your own thread.
With the solution of cgkmal you get a space between the first and second line, to avoid this you can use this:
awk '{printf("%s%s",$0,NR%2?"":ORS)}' file
awk 'ORS = NR%2 ? " " : "\n"' Source.txt
Here we use a conditional operator, the syntax is: expr ? action1 : action2
ORS = assign the value to the recordseparator ORS
NR%2 ? " " : "\n"
Here we look for the remainder of the division of the linenumber by 2 with the modulo operator %, odd lines give a 1 (true) and even lines give a 0 (false).
If the operator gives true (odd lines) the ORS is a space, otherwise the ORS is a newline.