-1

I have the following CSV format:

"/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 extract 2 values from each column, the first and the last value from the array, after the "=", like this:

"/opt=920MB;4855","/=4244MB;6359","/tmp=408MB;1109","/var=789MB;1859","/boot=53MB;729"

Per column it can work like this:

echo "$string" | awk 'BEGIN{FS=OFS=";"} {split($0,a,";"); print a[1],a[5]}'
/opt=920MB;4855

Any hints are highly appreciated.

2
  • What's up with your previous question - stackoverflow.com/q/51250515/5291015. Didn't that work out? Commented Jul 10, 2018 at 11:28
  • This is different from that one, this is to get 2 values from each column, not only one. Commented Jul 10, 2018 at 11:47

3 Answers 3

0
s/\([^;]*\);\([^;]*\)\[^"]*\([^;]*\);\([^;]*\)\[^"]*\([^;]*\);\([^;]*\)\[^"]*\([^;]*\);\([^;]*\)\[^"]*\([^;]*\);\([^;]*\)\[^"]*/\1;\2;\3;\4;\5;\6;\7;\8;\9;\10/
Sign up to request clarification or add additional context in comments.

1 Comment

Hi and welcome to Stack Overflow. While this answer might be amazing, could you please elaborate on it and explain a bit why this answers the question.
0

Found the solution by using sed:

echo "$string"| sed 's/=*;[^"]*;/,/g'

Comments

0

You can do it without sed that way :

xargs -d"\"" -n 1 -a file.csv | xargs -d";" | awk '/ key (start|stop) / {next} {if (match($0,"/")) printf("\"%s;%s\",",$1,$NF)} END {print ""}' |  rev | cut -c 2- | rev

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.