Hi,
I am parsing a file and extracting something based on some pattern
example.txt
f44942 f
f44942/Add.cpp f
s2018 s
f44942/Add2Numerics.cpp f
s3645 s
f44942/Add_scalar.cpp f
s2018 s
f44942/check_count_transform.cpp f
s2217 s
f44942/column_name.cpp f
s2402 s
f44942/column_name.so f
s426312 s
f44942/count_analytic1.cpp f
s2801 s
f44942/getperIns.sql f
s9273 s
fALTER_PARTITION f
fALTER_PARTITION/add_projection_refresh_test.sql f
s2747 s
fALTER_PARTITION/alter_partition_neg_test_1.sql f
s1965 s
fALTER_PARTITION/alter_partition_neg_test_2.sql f
s2494 s
fALTER_PARTITION/alter_partition_positive_test_1.sql f
s2496 s
I need the data in this format
450686,44942,directory
2018,44942/Add.cpp,file
3645,44942/Add2Numerics.cpp,file
2018,44942/Add_scalar.cpp,file
2217,44942/check_count_transform.cpp,file
2402,44942/column_name.cpp,file
426312,44942/column_name.so,file
2801,44942/count_analytic1.cpp,file
9273,44942/getperIns.sql,file
7206.ALTER_PARTITION,directory
2747,ALTER_PARTITION/add_projection_refresh_test.sql,file
1965,ALTER_PARTITION/alter_partition_neg_test_1.sql,file
2494,ALTER_PARTITION/alter_partition_neg_test_2.sql,file
directory have sum of size of all the files under the folder.
Till now I trim it down to certain level but stuck to proceed further - Please help.
cat example.txt | awk '{if(substr($1, 1, 1) == "s") {print$0","p} else {print $0}}{p=$0}' | grep -vE '^f.*/' |sed 's/ s,/,/;s/ f$//;s/^f//;s/,f/,/;s/^s//g'
44942
2018,44942/Add.cpp
3645,44942/Add2Numerics.cpp
2018,44942/Add_scalar.cpp
2217,44942/check_count_transform.cpp
2402,44942/column_name.cpp
426312,44942/column_name.so
2801,44942/count_analytic1.cpp
9273,44942/getperIns.sql
ALTER_PARTITION
2747,ALTER_PARTITION/add_projection_refresh_test.sql
1965,ALTER_PARTITION/alter_partition_neg_test_1.sql
2494,ALTER_PARTITION/alter_partition_neg_test_2.sql