how to fetch the particular columns

Sun / --
March 19, 2009 at 08:01:22
Specs: Linux, -
Hi all,


I have text file with 100 columns, i want to fetch the columns from 25th to 50 and from 75th to 100.
is there any better way to do that Instead of doing $25,$26,$27..etc like this

Thanks
MPS


See More: how to fetch the particular columns

Report •


#1
March 19, 2009 at 08:32:43
You can use something like awk or perl to parse the fields:


#!/bin/bash

# untested.  print fields 25 to 50
awk ' {

for (i=25; i<50; i++)
   printf("%s ", $i)

} '  datafile


Report •

#2
March 19, 2009 at 18:21:24
use cut
cut -f25-50,75-100 file


Report •

#3
March 20, 2009 at 04:02:13
Hi ghostdog and Nail

Cut and awk command is working which you have sent.

See the sample text file

15000202~6908689~20090227~3300000~USD~3301133~USD~1~3301133
15000202~6899106~20090227~5000000~USD~5004465.21~USD~1~5004465.21
15000202~6838040~20090227~3000000~USD~3001705.83~USD~1~3001705.83
15000202~6804325~20090227~7000000~USD~7041130.35~USD~1~7041130.35
15000202~6795094~20090227~5000000~USD~5011354.86~USD~1~5011354.86
15000202~6377755~20090227~3972000~USD~3982064.05~USD~1~3982064.05
15000202~5963134~20090227~8000000~USD~8195035.56~USD~1~8195035.56
15000202~3948912~20090227~925515.16~USD~925515.16~USD~1~925515.16

I want get the columns from 2nd to 9th, instead of using $2,$3,$4...$9. is there any other way to do that?

Thnaks
MPS


Report •

Related Solutions

#4
March 20, 2009 at 04:14:34
Hi ghostdog and Nail,

I got the solution using cut command itselt

the correct command is

cut -d"~" -f2-4 test.txt


Report •

#5
March 20, 2009 at 04:16:58
nails have shown you how to do it, in awk, using a for loop. I have shown you equivalent using the cut method. Please try to meddle around with the commands. the answer is already given.

Report •

#6
March 20, 2009 at 04:23:20
Hi ghostdog and Nail,

I got the solution using cut command itselt

the correct command is

cut -d"~" -f2-9 test.txt


Report •

#7
March 20, 2009 at 04:25:34
Yes ghostdog

Thanks for your help.

Regards,
MPS


Report •


Ask Question