1

Is that possible to split and align rows of CSV like below?

ID Value
========
1  10
--------
2  20
--------
3  14
--------

Please consider the above as a csv, no need to care about 2nd column (Value). I want to split the 1st Column (ID) and save the result/store it another file.

The output should like: 1,2,3

1
  • 1
    Welcome to Stack Overflow. Please improve your question by posting some properly formatted code you've applied to the problem. In addition, please take the time to share the steps you've taken so far to research or resolve things on your own. Commented Jan 10, 2013 at 16:58

2 Answers 2

1
awk '!/^[-=]/ && NR!=1{str=str","$1}END{print substr(str,2)}'

tested here

Sign up to request clarification or add additional context in comments.

Comments

1

Your problem is not well specified, but for your particular example you could do:

{ awk 'NR>2 && ! /^--/ { print $1 }' | tr \\n ,; echo; } < input > output

Or perhaps:

< input-file awk 'NR > 1 && NR%2 { print $1 }' | paste -d, -s > output

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.