Hi everyone..
I have a list of values in a file...
a,
b,
c,
1,
2,
3,
aaaa,
bbbbb,
I am interested in converting this column to a row..
"text",aaaa,
bbbb
a,1
b,2
c,3
can anyone pls help?? I am a newbie..
Thanks..
Hi everyone..
I have a list of values in a file...
a,
b,
c,
1,
2,
3,
aaaa,
bbbbb,
I am interested in converting this column to a row..
"text",aaaa,
bbbb
a,1
b,2
c,3
can anyone pls help?? I am a newbie..
Thanks..
Welcome to the forum.
Please become accustomed to provide decent context info of your problem.
It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.
Being a newbie, you might want to learn to "write" a decent specification (on top of the remarks here above) with due care, avoiding or, resp., answering questions before they arise. Here:
Why should anyone care more for your request than you do?
You are right, i try to integrate with more info. I would like to use awk or sed to sort the contents of a text file from row to column. I would like to convert:
a (text value),
b (text value),
c (text value),
1 (numeric value),
2 (numeric value),
3 (numeric value),
xxxxx (text value), yyyyy (text value)
in
"Zzzz", xxxxx, yyyyy
a, 1
b, 2
c, 3
Now I used
awk '{printf "% s% s", $ 0, NR% 4? "": "\ n"; } 'infile
but the result is:
a, b, c
1,2,3
xxxxx, yyyyy
Thanks
Again, there are some bits missing, and both input (I understand the explicatory text, but the space remains) and desired output are different from post#1.
"ZZZZ" is a fixed text to insert
the file is always 7 lines and the rule is to move line 7 to the top and then print lines 1 and 4, 2 and 5 and 3 and 6 comma-separated without space. No text or numeric controls are required
RudiC thanks for your time
Try
awk '
NR < 4 {T[NR] = $0
next
}
NR < 7 {sub (/,$/, _)
T[NR-3] = T[NR-3] FS $0
next
}
{print "\"Zzzz\",", $0
}
END {for (i=1; i<=3; i++) print T
}
' file
Thank you! It works!
Just another idea for fun...
set -- $( xargs -n2 <yourfile | sed 's/ .*//' | xargs )
echo -e "$7,$8,ZZZZZZ\n$1,$4\n$2,$5\n$3,$6\n"
(to be adapted )