Can somebody help me in solving this..
Input data is like
0 A
1 B
2 C
3 D
0 A1
1 B1
2 C1
3 D1
0 A2
1 B2
2 C2
3 D2
Output should be like
A B C D
A1 B1 C1 D1
A2 B2 C2 D2
Thanks in Advance
Can somebody help me in solving this..
Input data is like
0 A
1 B
2 C
3 D
0 A1
1 B1
2 C1
3 D1
0 A2
1 B2
2 C2
3 D2
Output should be like
A B C D
A1 B1 C1 D1
A2 B2 C2 D2
Thanks in Advance
awk '{print $2}' file | paste -d" " - - - -
sed -n 's/[0-3]//;s/ //;p' inputfile | awk -v ORS= '{print $0" ";if(NR%4==0){print "\n"}}'
Hi Itomuno, the command is working fine.Thanks a lot.....Is it possible to make it more generic like
INPUT:
0 A
1 B
2 C
- -
- -
- -
N XX
0 A1
1 B1
2 C1
- -
- -
- -
N XX1
0 A2
1 B2
2 C2
3 D3
- -
- -
N XX2
OUTPUT :
A B C D - - - -XX
A1 B1 C1 D1- - - -XX1
A2 B2 C2 D2 XX2
- - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - -
Where N can be any value
This will do it for any "N" and even if some lines are missing between 0+1 and N:
#!/usr/bin/ksh
mOutLine=""
while read mSeq mValue; do
if [[ "${mSeq}" = "0" ]]; then
if [[ "${mOutLine}" != "" ]]; then
echo ${mOutLine}
mOutLine=""
fi
fi
mOutLine=${mOutLine}' '${mValue}
done < input_file
if [[ "${mOutLine}" != "" ]]; then
echo ${mOutLine}
fi
Hi Shell_Life, after running your script, I am getting some error like
"[[: not found". I am not understanding what it is...Can you please solve this
What shell are you running it?
The shell was written to work with "ksh" as in the first line.
Type: "which ksh"
echo '0 A
1 B
2 C
- -
- -
- -
N XX
0 A1
1 B1
2 C1
- -
- -
- -
N XX1
0 A2
1 B2
2 C2
3 D3
- -
- -
N XX2' |awk '$1==0{print t;t=$2}{t=t FS $2}END{print t}'
A A B C - - - XX
A1 A1 B1 C1 - - - XX1
A2 A2 B2 C2 D3 - - XX2