how to cut fields in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to cut fields in file
# 1  
Old 05-13-2009
how to cut fields in file

Hi,
I have data in following format.

10001, John, Daves, Architecture, -2219
10002, Jim, Cirners, Businessman, -2219
1003, Tom, Katch, Engineer, -14003


I want to select the last column of the above given file and paste it on a different file in the following manner.
File TEST column 1, column 2, column 3
Code:
Column1                                          column 2      Column3
10001, John, Daves, Architecture       -2219              X
10002, Jim, Cirners, Businessman      -2219               Y
1003, Tom, Katch, Engineer              -14003             Z

Can you please help me to achive this as i very new to shell scripting.

Last edited by kam786sim; 05-13-2009 at 06:48 AM..
# 2  
Old 05-13-2009
# 3  
Old 05-13-2009
Thanks for reply.
But that example is for combining data from 2 files.

My input data is in 1 file only i have to keep first few coulmns same and only last column should be saprated .

And number of columns are also not same.
# 4  
Old 05-13-2009
From where your getting X Y Z ?....
# 5  
Old 05-13-2009
That i will do from the link u have given i want output for first 2 column now.
X Y Z are in diffrent file.

And i will get this from cut paste command you have suggested.
# 6  
Old 05-13-2009
You can use somethng like this
Code:
 
 
awk 'OFS="," { for(i=1;i<=NF-1;i++) printf("%s",$i);printf("\t%s",$NF); printf("\n") }' input_file

i am not sure whether it is wht ur expecting ?..
# 7  
Old 05-13-2009
its showing me all records as it is ..its not working..

see i have file

1,2,3
1,2,3
1,2,3

i want this records to be seprated as below

Code:
cloumn1      column2
1,2             3
1,2             3
1,2             3

This User Gave Thanks to kam786sim For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

2. Shell Programming and Scripting

How To Count Fields For Cut?

I am new to cut and I want to use the field option with a space delimiter on an Apache log file. For example, if I wanted to find the 200 HTTP code using cut in this manner on the file below cat access_abc.log | cut -d' ' -f7 | grep "200" 157.55.39.183 - - "GET /content/696-news041305... (4 Replies)
Discussion started by: sharingsunshine
4 Replies

3. UNIX for Dummies Questions & Answers

Cut fields between delimiters

I'm having bother getting both lines contained in a file to output as the same value. A simple example: john:123456:123:456:doe john:123456:123:doe cut -d: -f1,4 input file john:456 john:doe ^ first line should be same as second. trick one for me, i know why it's because of the... (4 Replies)
Discussion started by: landofus
4 Replies

4. Shell Programming and Scripting

Cut fields from /etc/passwd file into variables?

The script must ask the user to enter the user name and check whether the user exists in /etc/passwd (you must allow the partial usernames also). If the username exists, display the details as: List of users Login Name: User ID: ... (3 Replies)
Discussion started by: nobletechnology
3 Replies

5. Shell Programming and Scripting

Cut 2 fields and write to a output file

Hi, I am writing a code where the file is a pipe delimited and I would need to extract the 2nd part of field2 if it is "ATTN", "C/O" or "%" and check to see if field9 is populated or not. If field9 is already populated then leave it as is but if field9 is not populated then take the 2nd part of... (3 Replies)
Discussion started by: msalam65
3 Replies

6. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

7. UNIX for Dummies Questions & Answers

Cut specific fields from a file containing multiline records

Hi, I am looking for a method to get column13 to column 50 data from the 1st line of a multiline reord. The records are stored in a large file and are separated by newline. sample format is (data in red is to be extracted) <header> A001dfhskhfkdsh hajfhksdhfjh... (3 Replies)
Discussion started by: sunayana3112
3 Replies

8. Shell Programming and Scripting

cut: get either one or two fields

Hello, I would like to extract one or two fields of a line. At the moment, I am extracting the first field of a line: command | cut -f 1 -d '.' > file The line can have two or three fields delimited with a dot. if three fields, I want to be able to get the first two ie if line =... (3 Replies)
Discussion started by: maxvirrozeito
3 Replies

9. Shell Programming and Scripting

Cut Last 3 Fields

I have a text: dsj khfksjdh <time> EST 2006 ab cgnr jkkjt <time> EST 2006 gfhdgjghg <time> EST 2006 fkdjh kjhsekjrh kdjhfkh jhdfkhfdkjh kjdf <time> EST 2006 In the above file i need to extract time from every line... which is always the third from the last... Pls help! Cheers, Bouren (4 Replies)
Discussion started by: bourne
4 Replies

10. Shell Programming and Scripting

how to cut fields

I want to cut two coloums simulatiously and paste in some other file for ex: cut d ' ' -f3 -f4 xxx | paste yyy - > zzz; from the above i want to cut two fileds 3 and 4 and paste as last coloums of single file (zzz). how to solve this regards rajan (1 Reply)
Discussion started by: rajan_ka1
1 Replies
Login or Register to Ask a Question