awk '{while(gsub(/[|]/,"&")!=3 || $0 ~ /[|]$/){getline p;$0=$0 p}}1' file
This code seems working great on the sample!
Could someone kindly explain what it is doing? The regular expression here is kinda difficult for me...:wall:
awk -F\| 'NF{while(gsub(FS,"&")!=3 || $0 ~ /[|]$/){getline p;$0=$0 p}}1' file
Besides, I get error when I run this code.
I run it on a the sample file called "test1.txt" and get the following error.
awk: run time error: regular expression compile failed (missing operand)
|
FILENAME="test1.txt" FNR=1 NR=1
Is that I have missed something? I have put in the filename already.
---------- Post updated at 09:15 AM ---------- Previous update was at 08:58 AM ----------
This one also works!
Could you please kindly explain what's the meaning of the code?
---------- Post updated at 09:29 AM ---------- Previous update was at 09:15 AM ----------
---------- Post updated at 09:50 AM ---------- Previous update was at 09:29 AM ----------
sorry to all...i am confused...
there are so many solutions!
but each solution yields different results!!!
Here is the real data format for my case
12345|123456|999|D|1|123|1.2345|12.345|23.4567|||||||
987654|123456|999|O|12|99|2.3456|123.4567|345.6789|||||||Y
987654|123456|999|O|12|99|3.4567|123.4567|345.6789|||||||Y
987654|123456|999|O|12|99|4.5678|12.345|23.4567|||||||Y
987654|123456|999|O|12|99|5.6789|123.4567|345.6789|||||||Y
987654|123456|999|O|12|99|6.7890|123.4567|345.6789|||||||Y
987654|123456|999|H|1|1|34.5678|56.7890|67.8901||
|||||Y
987654|123456|999|E|1|1|2.3456|2.3456|2.34|||||||Y
.
.
.
totally i have 614293 lines in my data
I tried the following code which yielded 595647 lines in the result. (this one give me an error "new-line character seen in unquoted field" when i process it further using another script...:wall:)
sed -e 's/^|//g' -e 's/|$//g' source_data.csv | awk -F\| 'NF<16 || $16 == ""{getline p; $0=$0 FS p}1'>test1.csv
then i tried the following code which yielded 595433 lines in the result
awk '{while(gsub(/[|]/,"&")!=15 || $0 ~ /[|]$/){getline p;$0=$0 p}}1' source_data.csv>test2.csv
then i tried the following which yielded 595647 lines (this one also give me an error "new-line character seen in unquoted field" when i process it further using another script...:wall:)
awk -F\| '$16==x{getline p; $0=$0 p}1' A27.csv >test3.csv
I am totally confused on what's caused of the difference noted...and which code i should use...:wall: