Appending two files

Appending two files

Post by anju » Tue, 27 Jun 2006 14:19:19



Hi,

    I got a question. is there any single line command to merge two
files in a particular order ?

File 1
--------

Data1
Data2
Data3
Data4

File 2
--------

Data 11
Data 12
Data 13
Data14

Result expecting
------------------------

Data1 Data11
Data2 Data12
Data3 Data13
Data4 Data14

------------------------

Thanks in Advance,
An

 
 
 

Appending two files

Post by Chris F.A. Johnso » Tue, 27 Jun 2006 14:52:09



> Hi,

>     I got a question. is there any single line command to merge two
> files in a particular order ?

> File 1
> --------

> Data1
> Data2
> Data3
> Data4

> File 2
> --------

> Data 11
> Data 12
> Data 13
> Data14

> Result expecting
> ------------------------

> Data1 Data11
> Data2 Data12
> Data3 Data13
> Data4 Data14

paste File1 File2

    Read the man page for details.

--
   Chris F.A. Johnson, author              <http://cfaj.freeshell.org>
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   ===== My code in this post, if any, assumes the POSIX locale
   ===== and is released under the GNU General Public Licence

 
 
 

Appending two files

Post by anju » Tue, 27 Jun 2006 15:45:54




> > Hi,

> >     I got a question. is there any single line command to merge two
> > files in a particular order ?

> > File 1
> > --------

> > Data1
> > Data2
> > Data3
> > Data4

> > File 2
> > --------

> > Data 11
> > Data 12
> > Data 13
> > Data14

> > Result expecting
> > ------------------------

> > Data1 Data11
> > Data2 Data12
> > Data3 Data13
> > Data4 Data14

> paste File1 File2

>     Read the man page for details.

> --
>    Chris F.A. Johnson, author              <http://cfaj.freeshell.org>
>    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
>    ===== My code in this post, if any, assumes the POSIX locale
>    ===== and is released under the GNU General Public Licence

Hi,

Text1.txt
--------------

 Data1 Data11
 Data2 Data12
 Data3 Data13
 Data4 Data14

How can replace Second column values based on the first column...

Suppose, search for "Data2" value from the file and replace "Data12"
value with another value from the file.

Thanks in advance,
an

 
 
 

Appending two files

Post by Janis Papanagno » Tue, 27 Jun 2006 18:30:44



> Hi,

> Text1.txt
> --------------

>  Data1 Data11
>  Data2 Data12
>  Data3 Data13
>  Data4 Data14

> How can replace Second column values based on the first column...

> Suppose, search for "Data2" value from the file and replace "Data12"
> value with another value from the file.

   awk '$1 == "Data2" { $2 = "another value" } 1' <infile >outfile

Janis

- Show quoted text -

Quote:> Thanks in advance,
> an

 
 
 

1. HELP: Trying to combined two files (not append)

----------------------------------------------------------------

How about this, without using awk, for ksh:

sort f2.txt |  paste f1.txt - | unexpand -a | cut -f 1,2,4

This does the trick and sorts f2.txt but does not sort f1.txt.

Anyone know how to also sort f1.txt on the same command line?
i.e. In ksh, how can you invoke something like
sort f1.txt
and make it appear as if the output is a file, so it can be used
as a filename parameter?

John Healy              
Intel Ireland Ltd.
----------------------------------------------------------------
----------------------------------------------------------------

2. Convince boss of Linux over FreeBSD??

3. appending binary file in a text file

4. NEED a restricted shell

5. rsh question: Append local file to a remote file

6. mouse trouble

7. Help - how to append one file to every page of another file?

8. Load Balancing with two modems

9. Append to files in tar-file but don't change originals.

10. how to: remove last line from file 1 and append t0 file 2

11. how to append a file to another file

12. Appending a single file to multiple files

13. Appending a file into a top of a file.