Unix Shell - Pattern help

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2004 > Pattern help





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 Pattern help
suraj kumar

2004-05-17, 4:42 am

A file contains two lines

UAT 232333
UBS 2323322

I want the output in following format

UAT 233333 | UBS 2323322

Regards
Suraj
Chris F.A. Johnson

2004-05-17, 4:42 am

On 2004-05-17, suraj kumar wrote:
> A file contains two lines
>
> UAT 232333
> UBS 2323322
>
> I want the output in following format
>
> UAT 233333 | UBS 2323322


Do you just want the lines concatenated on a single line, or do
you want 232333 converted to 233333 as well (as per your example)?

To concatenate the lines:

{
read line1
read line2
} < FILE

printf "%s | %s" "$line1" "$line2"

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Web Surfer

2004-05-17, 9:52 am

[This followup was posted to comp.unix.shell]

In article <64719074.0405162348.56977b22@posting.google.com>,
suraj_c@hotmail.com says...
> A file contains two lines
>
> UAT 232333
> UBS 2323322
>
> I want the output in following format
>
> UAT 233333 | UBS 2323322
>
> Regards
> Suraj
>


rec1=`head -1 myfile.txt`
rec2=`tail -1 myfile.txt`
echo "$rec1 | $rec2`
rakesh sharma

2004-05-17, 12:39 pm

suraj_c@hotmail.com (suraj kumar) wrote in message news:

>
> A file contains two lines
>
> UAT 232333
> UBS 2323322
>
> I want the output in following format
>
> UAT 233333 | UBS 2323322
>


sed -e 'N;s/\n/ | /' yourfile
rakesh sharma

2004-05-17, 12:39 pm

suraj_c@hotmail.com (suraj kumar) wrote in message news:

>
> A file contains two lines
>
> UAT 232333
> UBS 2323322
>
> I want the output in following format
>
> UAT 233333 | UBS 2323322
>


sed -e 'N;s/\n/ | /' yourfile
Chris F.A. Johnson

2004-05-17, 5:38 pm

On 2004-05-17, Web Surfer wrote:
> [This followup was posted to comp.unix.shell]
>
> In article <64719074.0405162348.56977b22@posting.google.com>,
> suraj_c@hotmail.com says...
>
> rec1=`head -1 myfile.txt`
> rec2=`tail -1 myfile.txt`
> echo "$rec1 | $rec2`


Two unnecessary external commands; use the shell's read command:

{
IFS= read -r rec1
IFS= read -r rec2
} < myfile.txt

--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com