hi,
I have a file which consists of some records:
2010_06_4010093_001_001|10|ABCDEFGH|9|4010093||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00001|
2010_06_4010162_001_001|11|ABCDEFGH|9|4010162||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00002|
2010_06_4010163_001_001|17|ABCDEFGH|9|4010163||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00003|
I want to copy the first column (2010_06_4010093_001_001) to the last column on each row so that the file will look like
10|ABCDEFGH|9|4010093||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00001|2010_06_4010093_001_001|
11|ABCDEFGH|9|4010162||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00002|2010_06_4010162_001_001|
17|ABCDEFGH|9|4010163||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00003|2010_06_4010163_001_001|
Can someone please help me with this.
thanks
PP
sed 's/\([^|][^|]*|\)\(.*\)/\2\1/' myFile
2 Likes
cola
3
Please explain the regular expression.
1 Like
First create a new fich without the head
$ cut -d"|" -f2-25 asdf>fichNew
Sencond create a fich with the firt part what it will the last
$ cut -d"|" -f1 asdf>head
And paste the first part to the end and copy the result to FinalFich
$ paste -d '|' fichNew head>FinalFich
And its works it taste
�may can you vote me?
thanks
2 Likes
Thanks a lot. This worked.
1 Like
using bash:
cat pparthiv_file
2010_06_4010093_001_001|10|ABCDEFGH|9|4010093||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00001|
2010_06_4010162_001_001|11|ABCDEFGH|9|4010162||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00002|
2010_06_4010163_001_001|17|ABCDEFGH|9|4010163||0040400||31.12.2009|S|O|X||||20100602093851-31.12.2009|XXBBFC|EFG||||00003|
while IFS='|' read -a line; do
printf '%s|' "${line[@]:1}"
printf '%s|\n' "${line[@]::1}"
done < pparthiv_file
awk -F \| '{for (i=2;i<NF;i++) printf $i"|"} {print $1"|"}' urfile
1 Like
yes, awk is probably faster (even in this simple case? i'm not sure),
but your awk script/line misses to give the ending needed | on each line.
That's fine, it's not so difficult to update it, if the requester understands the code.
I have corrected it in previous post. .
err
now it adds an extra | between previously last field and kind_of_a_time stamp
cola
11
How would i print the output to a file?
while IFS='|' read -a line; do
printf '%s|' "${line[@]:1}"
printf '%s|\n' "${line[@]::1}"
done < pparthiv_file > anyother_file