Hi All,

I need to update a text file and I started with awk, which is already given great results, but I still miss a key component.

The scenario is that I have a file which is using # as a seperator. Though, it also has header lines including # which should be ignored.

Now there are some empty columns which can occure anywhere on the line, showing ## with nothing in between. For every line there are some dummy columns on the end that needs to be removed, but it can also be that the last real column would be empty too and then it should show the empty column by ##.

Example:

Let's say I have a file with 4 columns (A,B,C and D) Then my file can look like:

Header#with#many#crosses#which#should#be#ignored#i n#total.
data#test##test2###
home#here#there#test1###
hello######

So each line has 7 columns and the last 3 (dummy ones) needs to be removed. I can remove the crosses at the end of each file using gsub(/~+$/,"") but this gives me incorrect data for the last line, as it ends up having only hello and it is missing the 3 other columns.

I think I can split the file to seperate the header form the rest of the file, but I would prefer to have one awk script that can handle the file. This because I have multiple files with a different configuration that needs to be handled by the script. I just took this scenario out.

Can someone help me overcome this issue?

Thank you!