1

I have the following CSV format:

data_disk01,"/opt=920MB;4512;4917;0;4855","/=4244MB;5723;6041;0;6359","/tmp=408MB;998;1053;0;1109","/var=789MB;1673;1766;0;1859","/boot=53MB;656;692;0;729"

I would like to take from each column, except the first one, the last value from the array, like this:

data_disk01,"/opt=4855","/=6359","/tmp=1109","/var=1859","/boot=729"

I have tried something like:

awk 'BEGIN {FS=OFS=","} {if(NF==!1);gsub(/\=.*/,",")} 1'

Just the string, I managed to do it with:

string="/opt=920MB;4512;4917;0;4855"
echo $string | awk '{split($0,a,";"); print a[1],a[5]}' | sed 's#=.* #=#'
/opt=4855

But could not make it work for the whole CSV. Any hints are appreciated.

2 Answers 2

2

If your input never contains commas in the quoted fields, simple sed script should work:

sed 's/=[^"]*;/=/g' file.csv
Sign up to request clarification or add additional context in comments.

Comments

1

Could you please try following awk and let me know if this helps you.

awk '{gsub(/=[^"]*;/,"=")} 1' Input_file

In case you want to save output into Input_file then append > temp_file && mv temp_file Input_file in above code too.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.