|
Home > Archive > Unix Shell > October 2005 > using sed to move part of the string to start of the line
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
using sed to move part of the string to start of the line
|
|
| stephenfu1@gmail.com 2005-10-24, 3:45 pm |
| Hi
If i have a file that contains the 2 lines:
|[19:38:15,776] ||1
|[19:38:38,361] |x|||2
Is there a command to look for the last '|' and then move the data that
appears afterwards to the start of the line.
i.e would produce
1|[19:38:15,776] ||
2|[19:38:38,361] |x|||
Thanks
| |
| Steffen Schuler 2005-10-24, 3:45 pm |
| stephenfu1@gmail.com wrote:
> Hi
>
> If i have a file that contains the 2 lines:
>
> |[19:38:15,776] ||1
> |[19:38:38,361] |x|||2
>
> Is there a command to look for the last '|' and then move the data that
> appears afterwards to the start of the line.
>
> i.e would produce
>
> 1|[19:38:15,776] ||
> 2|[19:38:38,361] |x|||
>
> Thanks
>
awk 'BEGIN {FS="\\|";OFS="|"}
{$1=$NF; $NF=""; print}' file
| |
| Michael Tosch 2005-10-24, 3:45 pm |
| Steffen Schuler wrote:
> stephenfu1@gmail.com wrote:
>
>
> awk 'BEGIN {FS="\\|";OFS="|"}
> {$1=$NF; $NF=""; print}' file
shouldnt this be
awk 'BEGIN {FS=OFS="|"}
{$1=$NF; $NF=""; print}' file
Or
sed 's/\(.*|\)\(.*\)/\2\1/' file
--
Michael Tosch @ hp : com
| |
|
| sed 's:\(.*\)|\(.*\):\2\1|:' file
James
| |
| Enrique Perez-Terron 2005-10-24, 3:45 pm |
| On Thu, 20 Oct 2005 21:03:09 +0200, <stephenfu1@gmail.com> wrote:
> Hi
>
> If i have a file that contains the 2 lines:
>
> |[19:38:15,776] ||1
> |[19:38:38,361] |x|||2
>
> Is there a command to look for the last '|' and then move the data that
> appears afterwards to the start of the line.
>
> i.e would produce
>
> 1|[19:38:15,776] ||
> 2|[19:38:38,361] |x|||
sed 's/\(.*\)|\(.*\)/\2\1|/' infile > outfile
-Enrique
| |
| stephenfu1@gmail.com 2005-10-24, 3:45 pm |
| Thanks very much everyone, very much appreciated.
|
|
|
|
|