I have a file as:
I/P File:
Ground Car 2009
Lib 2008
Lib 2003
Ground Car 2009
Ground Car 2003
Car 2005
Car 2003
Car 2005
Sita 2900 2006
Car 2007
I have to split the file into two: - one for names and second for years.
O/p1 (Names):
Ground Car
Lib
Lib
Ground Car
Ground Car
Car
Car
Car
Sita 2900
Car
O/p 2 (Years):
2009
2008
2003
2009
2003
2005
2003
2005
2006
2007
Thanks!!!
# Print the last field into file2: print $NF >"file2"
# Remove the last field: $NF=""
# Print everything else into file1: print >"file1"
awk '{ print $NF >"file2" ; $NF="" ; print >"file1" }' < input
$
$ ls
data.txt
$
$ cat data.txt
Ground Car 2009
Lib 2008
Lib 2003
Ground Car 2009
Ground Car 2003
Car 2005
Car 2003
Car 2005
Sita 2900 2006
Car 2007
$
$
$ perl -lne 'BEGIN {open(F1, ">f1"); open(F2, ">f2")} m/^(.*?) (\d+)$/; print F1 $1; print F2 $2; END {close(F1); close(F2)}' data.txt
$
$
$ ls
data.txt f1 f2
$
$
$ cat f1
Ground Car
Lib
Lib
Ground Car
Ground Car
Car
Car
Car
Sita 2900
Car
$
$ cat f2
2009
2008
2003
2009
2003
2005
2003
2005
2006
2007
$
$
tyler_durden
Your idea was good! I have to test it.
Will post the result, after I test it!!!
Thanks.
---------- Post updated at 10:58 AM ---------- Previous update was at 10:55 AM ----------
Thanks for ur solution! But I don't have Idea on Perl .
---------- Post updated at 02:31 PM ---------- Previous update was at 10:58 AM ----------
Thank U, its worked for me!!!
---------- Post updated at 02:31 PM ---------- Previous update was at 02:31 PM ----------
Thank U, its worked for me!!!